Hello all,
I have an application dealing with User and Transaction objects, each transaction going from a source user to a target user.
I have defined the following associations in user.rb :
has_many :transactions_as_source, :class_name => "Transaction", :as => :source has_many :transactions_as_target, :class_name => "Transaction", :as => :target
and this is working fine, but I'm looking for a way to define "has_many :transactions" to get all the transactions having the user as a source *OR* a target, i.e. something like:
has_many :transactions, :finder_sql => 'SELECT * FROM transactions WHERE source_id = #{id} OR target_id = #{id}'
but without resorting to finder_sql (as with this definition I cannot cascade additional queries such as current_user.transactions.sum(:amount) or current_user.transactions.find(...).
Thanks,
Nicolas