Eri*_*rch 41 ruby code-formatting
我们如何编写以下语句以提高可读性?
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)
Run Code Online (Sandbox Code Playgroud)
以下内容无法编译
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])
Run Code Online (Sandbox Code Playgroud)
Eri*_*rch 56
也有可能做到
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)
Run Code Online (Sandbox Code Playgroud)
Geo*_*Geo 50
像这样做:
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24504 次 |
| 最近记录: |