you need to use :source on the :through association<br><br>basically the way :through works is that it tries to infer the name of the name of the association, but in your case it can't<br><br>if you don't use :source, the has_many will try to find an association called :supported_products in the mechant class, but it can't, there is only :products, and that is what :source does, it says, "look for this association in the join class".
<br><br>I'm new to :through as well, but this is what it seems to be intended for.<br><br>class Employee < ActiveRecord::Base<br> has_many :enrolled_merchants, :class_name => "Merchant", :foreign_key => "enrollment_employee_id"
<br> has_many :supported_merchants, :class_name => "Merchant", :foreign_key => "support_employee_id"<br> has_many :enrolled_products, :through => :enrolled_merchants, :source => :products
<br>
has_many :supported_products, :through => :supported_merchants, :source => :products<br>
end<br><br>class Merchant < ActiveRecord::Base<br> belongs_to :enrollment_employee, :class_name => "Employee"<br>
belongs_to :support_employee, :class_name => "Employee"<br> has_many :products<br>end<br><br>class Product < ActiveRecord::Base<br> belongs_to :merchant<br>end<br><br><div><span class="gmail_quote">On 3/31/06,
<b class="gmail_sendername">Chris Hall</b> <<a href="mailto:christopher.k.hall@gmail.com">christopher.k.hall@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div style="direction: ltr;"><span class="e" id="q_10a5144de8f60e8b_0"><br><div><span class="gmail_quote">On 3/31/06, <b class="gmail_sendername">Stephen Gerstacker</b> <<a href="mailto:stephen@shortround.net" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
stephen@shortround.net</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Quick Overview:<br><br>I have an 'Employee', some 'Merchants' and some 'Products'. A<br>'Merchant' has many 'Products'. An 'Employee' has multiple 'Merchants',<br>depending on their relationship. For example, the Employee may be the
<br>enrollment contact for one merchant and the support contact for another.<br>Therefore, my Employee class looks like this:<br><br>class Employee < ActiveRecord::Base<br><br> has_many :enrollment_merchants, :class_name => "Merchant",
<br>:foreign_key => :enrollment_employee_id<br> has_many :support_merchants, :class_name => "Merchant", :foreign_key<br>=> :support_employee_id<br><br>end<br><br>And my Merchant class looks like this:
<br>
<br>class Merchant < ActiveRecord::Base<br><br> belongs_to :enrollment_employee, :class_name => "Employee",<br>:foreign_key => "enrollment_employee_id"<br> belongs_to :support_employee, :class_name => "Employee", :foreign_key
<br>=> "support_employee_id"<br><br> has_many :products<br><br>end<br><br>I'd like to use :through in the association so that I can get all of the<br>enrollment products and all of the support products for the Employee.
<br>Ideally it would look like:<br><br>class Employee < ActiveRecord::Base<br><br> has_many :enrollment_merchants, :class_name => "Merchant",<br>:foreign_key => :enrollment_employee_id<br> has_many :support_merchants, :class_name => "Merchant", :foreign_key
<br>=> :support_employee_id<br><br> has_many :enrollment_products, :through => :enrollment_merchants<br> has_many :support_products, :through => :support_merchants<br><br>end<br><br>But that obviously doesn't work. Can I make this work somehow?
<br><br>--<br>Posted via <a href="http://www.ruby-forum.com/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.ruby-forum.com/</a>.<br>_______________________________________________<br>Rails mailing list
<br><a href="mailto:Rails@lists.rubyonrails.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Rails@lists.rubyonrails.org
</a><br><a href="http://lists.rubyonrails.org/mailman/listinfo/rails" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://lists.rubyonrails.org/mailman/listinfo/rails</a><br></blockquote></div><br>
</span></div></blockquote></div><br>