[Rails] Re: Calculate methods on attr_accessor objects
François Montel
zerohalo at gmail.com
Thu Jul 27 19:30:36 GMT 2006
Thanks, Kevin. That didn't work, but it got me going in the right
direction.
Through a bit of trial and error I discovered that contrary to what the
AR rdoc says, count_by_sql accepts other methods than just COUNT.
So this works:
Item.count_by_sql("select sum(cost_unit * amount) from items")
Not very "rails like" though :-(. I should probably write a
calculate_by_sql helper that accepts all the various calculate commands
for those instances where you need more than just the sum of a single
column or where that column doesn't exist.
Kevin Olbrich wrote:
> Something like this may work...
>
> Item.sum(:select=>'(cost_unit + amount)')
--
Posted via http://www.ruby-forum.com/.
More information about the Rails
mailing list