I want to define a custom method for an activerecord relationship, for example:
Transaction.all.summed_values
A simple example: where summed_valuesshould evaluate sum(:value)in relation.
Where should I define a method summed_values? Looks like he should be on ActiveRecord::Relation. If it should be directly there, in which file should I put it?
Also, if this new method makes sense only for Transactions, is there a way to tell the rails to only define this method for ActiveRecord::Relationwhich consists of Transactions?
source
share