Forum: Ruby on Rails preloading child rows just a level deeper...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1843714391c0cdbec384182760833ee6?d=identicon&s=25 Gerald Schenke (Guest)
on 2006-04-10 20:30
hiho.

following problem.
i have 3 tables in my database with each representing an object.
lets say
A belongs_to B belongs_to C.

when i do
my_a = A.find(:all)
i can access B as my_a.b and C as my_a.b.c
thats fine but rails querys the database each time i do that

so is use
my_a = A.find(:all, :include => :b)
works fine for my_a.b but not for my_a.b.c

so i tried
my_a = A.find(:all, :include => [:b, :c])
but that gives an error:
"Association named 'c' was not found; perhaps you misspelled it?"

well, no i didnt misspelled, but table A dont has an c_id. only table B
knows to what c it belongs
no wonder there is an error ... :/

question is:
Can i preload the rows of C like i do it with the rows in B when i query
table A?

i hope i made it clear enough... :/

[ No, i cant/dont want to use STI ]
41e1579600683eed6c00af9a425268e6?d=identicon&s=25 Edward Frederick (Guest)
on 2006-04-10 21:22
(Received via mailing list)
Gerald,

Try googling for 'rails bottomless eager loading'--new feature in 1.1,
I believe.


--

Ed Frederick - edwardfrederick.com
41e1579600683eed6c00af9a425268e6?d=identicon&s=25 Edward Frederick (Guest)
on 2006-04-10 21:25
(Received via mailing list)
To follow up my previous reply:

try: A.find(:all, :include => { :b => { :c })
1843714391c0cdbec384182760833ee6?d=identicon&s=25 Gerald Schenke (azrael)
on 2006-04-10 21:40
thank you so much!
awesome!!!
This topic is locked and can not be replied to.