Daya Sharma
2008-Apr-21 23:43 UTC
Lost Polymorphic Associations in development environment causes delegate :blah, :to => to fail
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Maybe Matching Threads
- Can't eagerly load a polymorphic association defined in an STI parent class?
- Problem with belongs_to associations validating associated class: bug in rails in development mode?
- Database performance for polymorphic associations under high load
- Polymorphic Associations: dynamic finders
- Eager loading of polymorphic associations