# Strange eager loading issues

**URL:** <https://www.ruby-forum.com/t/strange-eager-loading-issues/139754>\
**Category:** Rails\
**Created:** [June 6, 2008, 6:39pm UTC](https://www.ruby-forum.com/t/strange-eager-loading-issues/139754 "2008-06-06T18:39:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sean\_OSHara](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dbc845/32.png) [@Sean\_OSHara](https://www.ruby-forum.com/u/Sean_OSHara)\
**Post date:** [June 6, 2008, 6:39pm UTC](https://www.ruby-forum.com/t/strange-eager-loading-issues/139754/1 "2008-06-06T18:39:30Z")

</div>

Hi,  
I am having trouble with eager loading in my app. It used to work all  
the  
time, but since upgrading to rails 2.0.2, and now rails 2.1, it doesn’t  
work  
with many of my queries. For example, this find is loaded eagerly:

@release = Release.find\_by\_url(params[:id],  
:include =\> [{:artist =\> :artist\_images}, {:songs =\> :track},  
:collection, :hard\_products, :release\_images, :label],  
:conditions =\> [“labels.name=? OR labels.name=? OR  
labels.name=?”,  
“Alien8 Recordings”, “Fancy”, “Substractif”])

but this find is not (and it is a simpler query):

@release = Release.find\_by\_url(params[:id],  
:include =\> [{:songs =\> :track}, :collection, :hard\_products])

FYI, here’s my model relationships:

class Release \< ActiveRecord::Base  
belongs\_to :artist  
belongs\_to :label  
has\_many :release\_images, :dependent =\> :destroy  
has\_many :hard\_products  
has\_many :songs  
has\_one :collection  
end

class Song \< Product  
belongs\_to :release  
has\_one :track, :dependent =\> :destroy  
end

class Track \< ActiveRecord::Base  
belongs\_to :song  
belongs\_to :collection  
end

class Collection \< Product  
has\_many :tracks  
belongs\_to :release  
end

Does anyone know how to force rails to load eagerly?

---

<div class="post-metadata">

**Author:** ![Sean\_OSHara](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dbc845/32.png) [@Sean\_OSHara](https://www.ruby-forum.com/u/Sean_OSHara)\
**Post date:** [June 7, 2008, 11:34am UTC](https://www.ruby-forum.com/t/strange-eager-loading-issues/139754/2 "2008-06-07T11:34:29Z")

</div>

On Jun 6, 5:38 pm, “Sean O’Hara” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,  
> I am having trouble with eager loading in my app. It used to work all the  
> time, but since upgrading to rails 2.0.2, and now rails 2.1, it doesn’t work  
> with many of my queries. For example, this find is loaded eagerly:

If the difference you are seeing only occurred when moving from 2.0.2  
to 2.1 then part of what you are seing could be the changes made to  
eager loading in rails 2.1 (I wrote about some of them at  
[Mixing :include and :conditions - Space Vatican](http://www.spacevatican.org/2008/4/29/include-and-conditions))

Fred
