# Preloading child rows just a level deeper

**URL:** <https://www.ruby-forum.com/t/preloading-child-rows-just-a-level-deeper/57422>\
**Category:** Rails\
**Created:** [April 10, 2006, 8:30pm UTC](https://www.ruby-forum.com/t/preloading-child-rows-just-a-level-deeper/57422 "2006-04-10T20:30:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gerald\_Schenke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/7ba0ec/32.png) [@Gerald\_Schenke](https://www.ruby-forum.com/u/Gerald_Schenke)\
**Post date:** [April 10, 2006, 8:30pm UTC](https://www.ruby-forum.com/t/preloading-child-rows-just-a-level-deeper/57422/1 "2006-04-10T20:30:39Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![Gerald\_Schenke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/7ba0ec/32.png) [@Gerald\_Schenke](https://www.ruby-forum.com/u/Gerald_Schenke)\
**Post date:** [April 10, 2006, 9:22pm UTC](https://www.ruby-forum.com/t/preloading-child-rows-just-a-level-deeper/57422/2 "2006-04-10T21:22:49Z")

</div>

Gerald,

Try googling for ‘rails bottomless eager loading’–new feature in 1.1,  
I believe.

–

Ed Frederick - [edwardfrederick.com](http://edwardfrederick.com)

---

<div class="post-metadata">

**Author:** ![Gerald\_Schenke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/7ba0ec/32.png) [@Gerald\_Schenke](https://www.ruby-forum.com/u/Gerald_Schenke)\
**Post date:** [April 10, 2006, 9:25pm UTC](https://www.ruby-forum.com/t/preloading-child-rows-just-a-level-deeper/57422/3 "2006-04-10T21:25:52Z")

</div>

To follow up my previous reply:

try: A.find(:all, :include =\> { :b =\> { :c })

---

<div class="post-metadata">

**Author:** ![Gerald\_Schenke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/7ba0ec/32.png) [@Gerald\_Schenke](https://www.ruby-forum.com/u/Gerald_Schenke)\
**Post date:** [April 10, 2006, 9:40pm UTC](https://www.ruby-forum.com/t/preloading-child-rows-just-a-level-deeper/57422/4 "2006-04-10T21:40:35Z")

</div>

thank you so much!  
awesome!!!
