Ответ 1
Сделайте это так:
Promotion.joins(:category).
where(["lft>=? and rgt<=?", c.lft, c.rgt]).
joins(:shops).
where(:promotions_per_shops => { :shop_id => shops_id }).
count('id', :distinct => true)
Как написать следующую инструкцию для улучшения удобочитаемости?
Promotion.joins(:category).where(["lft>=? and rgt<=?", c.lft, c.rgt]).joins(:shops).where(:promotions_per_shops => { :shop_id => shops_id }).count('id', :distinct => true)
Ниже не компилируется
Promotion.joins(:category)
.where(["lft>=? and rgt<=?", c.lft, c.rgt])
.joins(:shops)
.where(:promotions_per_shops => { :shop_id => shops_id })
.count('id', :distinct => true)
syntax error, unexpected '.', expecting kEND
.where(["lft>=? and rgt<=?", c.lft, c.rgt])
Сделайте это так:
Promotion.joins(:category).
where(["lft>=? and rgt<=?", c.lft, c.rgt]).
joins(:shops).
where(:promotions_per_shops => { :shop_id => shops_id }).
count('id', :distinct => true)
Также возможно сделать
Promotion.joins(:category) \
.where(["lft>=? and rgt<=?", c.lft, c.rgt]) \
.joins(:shops) \
.where(:promotions_per_shops => { :shop_id => shops_id }) \
.count('id', :distinct => true)
Он должен скомпилировать в 1.9. В предыдущих версиях это действительно было неверно.