I have such angry associations: financings >- events >- subprograms >- programs. I want to get acces to last_financings from programs through all of them so code is:
<
As far as I remember you can't make association with double (or more) :through. The only thing you can do is write your own sql queries.
Here is my example how to do it:
class Person
...
has_many :teams, :finder_sql =>
'SELECT DISTINCT teams.* FROM teams
INNER JOIN team_roles ON teams.id = team_roles.team_id
INNER JOIN team_members ON team_roles.id = team_members.role_id
WHERE ((team_members.person_id = #{id}))'
# other standard associations
has_many :team_members
has_many :team_roles,
:through => :team_members
# and I couldn't do:
# has_many :teams, :through => :team_roles
This is for relation Person -> has_many -> team_members -> has_many -> team_roles -> has_one - team.
Hope it helps.
This seems like a really awkward way of doing this... I'd rather make a virtual accessor in Program
that calls something like this:
self.subprograms.first.events.first.financings.first(:order => 'date DESC')
The error you get is about source_reflection is an invalid association, because source for has_many through must be belongs_to, has_one or has_many without through option. So you can't use :last_actual_financings as a source.