Is there a particularly elegant way to make a count request with Rails 3 / Arel?

Here's the Rails2 request:

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 perfect.

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

change

it's prettier, but still not Areca's magic:

 Foo.count( :conditions => "bar = 'a-bar' and baz = 'a-baz'" ) 
+4
source share
1 answer
 Foo.where(['bar = ? and baz = ?', 'a-bar', 'a-baz']).count 
+7
source

All Articles