How can we write the following statement to improve readability?
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)
The following doesn't compile
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])
Also possible to do
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)
Do it like this:
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With