I have a Company that has_and_belongs_to_many Persons. A Person
has_many Emails. I want to display each Person’s Email for each
Company, so I try this:
companies = Company.find(:all)
for company in companies
persons = company.persons
for person in persons
Unfortunately, this doesn’t work correctly. Let’s say the id of the
first company is 22, and the associated person’s id is 218.
ActiveRecord is retrieving from the Emails table where the owner =
22, NOT where the owner = 218, or the id of the Person.
Is this the way that ActiveRecord is supposed to work? I thought that
when I ask for an associated object, that object would be related to
the object that is associated to it, not an object higher up in the
What’s the best work-around for this, or am I on the wrong path?