Sunday, 15 August 2010

ruby on rails - How to get records through a many-to-many association? -



ruby on rails - How to get records through a many-to-many association? -

i have these models in rails 4 app:

class invoice < activerecord::base has_many :allocations has_many :payments, :through => :allocations end class allocation < activerecord::base belongs_to :invoice belongs_to :payment end class payment < activerecord::base has_many :allocations has_many :invoices, :through => :allocations end

how can invoices related 1 particular payment x?

i've been trying head around day no avail.

thanks help.

as simple as:

payment.invoices

this follow association, passing through allocation model.

ruby-on-rails ruby activerecord

No comments:

Post a Comment