Can you reference the properties of a join table in a has_many :through relationship?
Classic join relationship:
class Committee
has_many :positions
has_many :members, through: :positions
end
class Member
has_many :positions
end
class Positions
belongs_to :committee
belongs_to :member
attr_accessible :description
end
This gives us a nice way to access members directly from the Committee:
c = Factory :committee
first_member = members.first
Accessing information on the join table via the association
Is there some way to reference the description of the position (which exists on the join table) from this relationship?
e.g.
first_member_description = members.first.proxy.description
If not then what’s the cleanest way to access the description of a particular committee member?
Why would I want to do this?
I want to do this because I want to find a committee member by name and then find their description:
i.e.
peters_description = committee.members.find_by_first_name('Peter').proxy.description
You could add the finder on the Position class:
This should allow you to do: