# Lost Polymorphic Associations in development environment causes delegate :blah, :to =\> to fail

**URL:** <https://www.ruby-forum.com/t/lost-polymorphic-associations-in-development-environment-causes-delegate-blah-to-to-fail/135420>\
**Category:** Rails\
**Created:** [April 22, 2008, 2:00am UTC](https://www.ruby-forum.com/t/lost-polymorphic-associations-in-development-environment-causes-delegate-blah-to-to-fail/135420 "2008-04-22T02:00:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![daya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9fc348/32.png) [@daya](https://www.ruby-forum.com/u/daya)\
**Post date:** [April 22, 2008, 2:00am UTC](https://www.ruby-forum.com/t/lost-polymorphic-associations-in-development-environment-causes-delegate-blah-to-to-fail/135420/1 "2008-04-22T02:00:19Z")

</div>

Hi All

I have been struggling with this issue for a long time now. And before  
I began to describe the problem its important to know that this  
problem happens only in Development environment.

I am using Rails 2.0.2, here are my associations

class User  
has\_many :comments  
has\_one :profile, :as =\> :profileable  
delegate :email, :to =\> :profile

end

First call to comment.user.email works just fine the associated  
profile object gets loaded and the delegation occurs just fine.

However, a second/subsequent call to comment.user.email throws  
ActiveRecord::ConfigurationError: Association named ‘profile’ was not  
found; perhaps you misspelled it?

The solution I have tried are and none have worked are

1). put a require\_dependency ‘models/profile’ in environment.rb  
2). put a require ‘models/profile’ in models/user.rb  
3). put a load ‘models/profile.rb’ in models/user.rb  
4).  
class User

def before\_initialization  
Profile.find(1) #just to load the Profile class, I know this looks  
stupid and desperate  
end

end

The only solution that works is

config.cache\_classes = true #in development.rb

but as you know this is not acceptable.

Any ideas, what might be causing this bug and how I can fix it.

Regards,  
-daya
