# After upgrading to Rails 2.3.4, Lazy Loaded attributes are never loaded. Broken?

**URL:** <https://www.ruby-forum.com/t/after-upgrading-to-rails-2-3-4-lazy-loaded-attributes-are-never-loaded-broken/178779>\
**Category:** Rails\
**Created:** [November 11, 2009, 8:28am UTC](https://www.ruby-forum.com/t/after-upgrading-to-rails-2-3-4-lazy-loaded-attributes-are-never-loaded-broken/178779 "2009-11-11T08:28:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [November 11, 2009, 8:28am UTC](https://www.ruby-forum.com/t/after-upgrading-to-rails-2-3-4-lazy-loaded-attributes-are-never-loaded-broken/178779/1 "2009-11-11T08:28:24Z")

</div>

I have an application that I started developing under 2.1 and have  
progressed through 2.2 and am no attempting to run using 2.3.4.

The application is heavily reliant on ActiveRecord and the ability to  
reference objects and attributes using dot notation.

eg:

if I have defined for class ARec  
named\_scope :for\_period, lambda {|f,t| {:conditions =\> [‘from\_date  
between ? and ?’, f,t]}}

I typically call:  
from\_date = ARec.for\_period( c.d.e.from, f.g.h.i.to )

or similar within my code.

The problem is that under 2.2.2, c.d.e.from and f.g.h.i.to both loaded  
the values from the database as needed, whereas under 2.3.4, when I  
run the same code block, the from and to calls both get into  
AssociationProxy.load\_target (association\_proxy.rb : 237) and Rails  
determines that the instances have already been loaded, even though  
their attribute lists are nil.

The only solution I have found so far is to add a parameter of true to  
each object to force the loading. But I don’t really want to do that  
to the over 10,000 places in my code where I may need to do this.  
What this really seems to indicate is that lazy loading of objects is  
broken in Rails 2.3.4 if AR is marking records as loaded when it  
hasn’t loaded the attributes.

What can I do (short of going back to Rails 2.2.x) to get Lazy Loading  
working application wide for a system with over 400 separate models  
and over 20,000 lines of code in my models?

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [November 11, 2009, 10:26am UTC](https://www.ruby-forum.com/t/after-upgrading-to-rails-2-3-4-lazy-loaded-attributes-are-never-loaded-broken/178779/2 "2009-11-11T10:26:04Z")

</div>

On Nov 11, 7:25 am, Polydectes [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have an application that I started developing under 2.1 and have  
> progressed through 2.2 and am no attempting to run using 2.3.4.
> 
> The application is heavily reliant on ActiveRecord and the ability to  
> reference objects and attributes using dot notation.

I think that applies to most applications and is something that should  
just work. Have you tried boiling down your problem to an example  
small enough to post here ?

Fred

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [November 12, 2009, 11:09am UTC](https://www.ruby-forum.com/t/after-upgrading-to-rails-2-3-4-lazy-loaded-attributes-are-never-loaded-broken/178779/3 "2009-11-12T11:09:53Z")

</div>

On Nov 12, 7:44 am, Polydectes [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> loc = ARec.location( true )
> 
> the result is a Location object in loc with @attributes,  
> @attributes\_cache, and all records related to the Location class set  
> to nil.
> 
> I have created a small project (using NetBeans 6.8, Ruby 1.8.7, and  
> Rails 2.3.4) which shows the failure when you run “rake test:units”

What does the code for that project look like ?

Fred

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [November 12, 2009, 8:45am UTC](https://www.ruby-forum.com/t/after-upgrading-to-rails-2-3-4-lazy-loaded-attributes-are-never-loaded-broken/178779/4 "2009-11-12T08:45:51Z")

</div>

I am trying to narrow this down as much as possible. The problem is  
that it’s so prevalent that I have dome the following:

Assuming the ARec from above contains a has\_one relationship to a  
Location such that  
ARec.location is the related location.

In my code, I have the ARec loaded and I want to get the Location. So  
I do the following:

loc = ARec.location( true )

the result is a Location object in loc with @attributes,  
@attributes\_cache, and all records related to the Location class set  
to nil.

I have created a small project (using NetBeans 6.8, Ruby 1.8.7, and  
Rails 2.3.4) which shows the failure when you run “rake test:units”

On Nov 11, 3:24 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [November 12, 2009, 3:01pm UTC](https://www.ruby-forum.com/t/after-upgrading-to-rails-2-3-4-lazy-loaded-attributes-are-never-loaded-broken/178779/5 "2009-11-12T15:01:04Z")

</div>

Eric Smith wrote:  
[…]

> What can I do (short of going back to Rails 2.2.x) to get Lazy Loading  
> working application wide for a system with over 400 separate models  
> and over 20,000 lines of code in my models?

This is a side issue, but…refactor your codebase! It’s a rare  
application indeed that needs 400 models, so I suspect you may have some  
stuff that should come out…

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
