deeply nested models

0 views
Skip to first unread message

Ant

unread,
Jun 16, 2008, 10:48:16 AM6/16/08
to nested_has_many_through
Hi Ian

Thanks for putting this plugin up on github. It's just what I'm
looking for. I have a quick question suppose I have this deeply nested
model structure


model A
has_many :as

model B
belongs_to :a
has_many :cs

model C
belongs_to :b
has_many :ds

model D
belongs_to :c
has_many :es

model E
belongs_to :d


If I would like to access all model As model Es via the command

A.find(1).es

I have found I can get this to work by adjusting model A to the
follwoing

model A
has_many bs
has_many cs, :through => :bs
has_many ds, :through => cs, :source => ds
has_many es, :through => ds, :source =>es


I got to this point by trial and error and reading some of the errors
produced on the console. 2 questions:
1) I don't really understand what the :source parameter is doing.
Would you mind giving a quick explanation
2) I feel there may be a better (nested?) way of doing this since at
the moment B.find(1).es wouldn't work without putting fairly similar
code into model B and it would end up not very DRY.


Many thanks

Anthony
Reply all
Reply to author
Forward
0 new messages