I have an ActiveRecord model that has two database attributes, total and processing_fees.
It has various scopes defined, such as (just as examples):
class Item < ActiveRecord::Base
scope :completed, joins(:order).where(:orders => {:status => Order::Status::COMPLETED})
scope :for_client, lambda {|client| where("client_id=?", client.id)}
...etc...
end
I can easily do something like:
Item.completed.for_client(client).sum(:total)
but what I would like to do is something like:
Item.completed.for_client(client).calculate(:total - :processing_fees) # obv not valid
Is there any way to do such a thing?
Something like this should work: