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
精彩评论