I think you misunderstood, so let me rephrase. I've got an AR-derived
class (ActorTag) with a set of associations. The first controller
action completes perfectly, but on the second I get an error in my
AR-derived class in which an association necessary for find(...,
:include => ...) is not found. It turns out that it is using the same
class object in both requests (although it should have been reloaded,
given that cache_classes=false) except that by the time it hits the
second one the reflections attribute has been reset to nil. None of
this happens if cache_classes has been set to true.
Now, I have verified that this is the same class by examining the
object_id's of the ActorTag class object. I have also verified the
lack of reload by placing a breakpoint in my class definition code
(which gets triggered exactly once). Placing 'assert { not
base.reflections.empty? }' in
ActiveRecord::Associations::ClassMethods::JoinDependency#initialize
produces a break and I can engage in this particular dialogue:
irb(#<ActiveRecord::Associations::ClassMethods::JoinDependency:0x3448438>):001:0>
base
=> ActorTag
irb(#<ActiveRecord::Associations::ClassMethods::JoinDependency:0x3448438>):002:0>
ActorTag
=> ActorTag
irb(#<ActiveRecord::Associations::ClassMethods::JoinDependency:0x3448438>):003:0>
ActorTag.object_id
=> 28185842
irb(#<ActiveRecord::Associations::ClassMethods::JoinDependency:0x3448438>):004:0>
base.object_id
=> 28406902
irb(#<ActiveRecord::Associations::ClassMethods::JoinDependency:0x3448438>):005:0>
ActorTag.reflections
=> {:actor=>#<ActiveRecord::Reflection::AssociationReflection:0x35c2840
@primary_key_name="actor_id", @through_reflection=false, @name=:actor,
@class_name="Actor", @active_record=ActorTag, @options={},
@macro=:belongs_to>,
:bookmarks=>#<ActiveRecord::Reflection::AssociationReflection:0x35b48d0
@primary_key_name="actor_tag_id", @name=:bookmarks,
@active_record=ActorTag, @options={:through=>:url_tags},
@macro=:has_many>,
:notes=>#<ActiveRecord::Reflection::AssociationReflection:0x35ae05c
@primary_key_name="actor_tag_id", @name=:notes,
@active_record=ActorTag, @options={:through=>:url_tags},
@macro=:has_many>,
:url_tags=>#<ActiveRecord::Reflection::AssociationReflection:0x35bd278
@primary_key_name="actor_tag_id", @name=:url_tags,
@active_record=ActorTag, @options={:dependent=>:destroy,
:include=>[:tag, :link]}, @macro=:has_many>,
:tag=>#<ActiveRecord::Reflection::AssociationReflection:0x35c0e78
@primary_key_name="tag_id", @through_reflection=false, @name=:tag,
@class_name="Tag", @active_record=ActorTag, @options={},
@macro=:belongs_to>,
:links=>#<ActiveRecord::Reflection::AssociationReflection:0x35b8b9c
@primary_key_name="actor_tag_id", @name=:links,
@active_record=ActorTag, @options={:through=>:url_tags},
@macro=:has_many>}
irb(#<ActiveRecord::Associations::ClassMethods::JoinDependency:0x3448438>):006:0>
base.reflections
=> {}
So... The base passed in to JoinDependency#initialize is an ActorTag
class with reflections cleared to nil. When I access the ActorTag
class *by name*, I get a different object with a proper reflections
array. Am I wrong to think that something has screwed up in signalling
that the class should be automatically reloaded on reference? It wasn't
reloaded when it should have been, and I'm now seeing a class with the
right name, but messed-up contents.