开发者

Is there a particularly elegant way to do a count query with Rails 3 / Arel?

H开发者_C百科ere's a Rails2 query:

Foo.find_by_bar_and_baz('a-bar', 'a-baz', :select =>'count(*) as the_count' ).the_count.to_i

The query is ugly, but the resulting SQL is ideal.

Is there a more elegant way to do this in Rails 3 / Arel?

edit

this is prettier but still no Arel magic:

Foo.count( :conditions => "bar = 'a-bar' and baz = 'a-baz'" )


Foo.where(['bar = ? and baz = ?', 'a-bar', 'a-baz']).count
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜