Forum: Ruby on Rails Using variable class names breaks has_many?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3b330e8ad92a811462ce777b10651c4f?d=identicon&s=25 Isaac Reuben (Guest)
on 2006-04-18 01:23
(Received via mailing list)
Hey All,

Any idea why this would work this this:

class Dog
  has_many :fleas
end

dog = Dog.find_first
dog.name   =>  "Buster"
dog.class   =>  Dog
dog.fleas    =>  []

# store the class
animal_class = dog.class   =>  Dog

dog = animal_class.find_first
dog.name   =>  "Buster"
dog.class   =>  Dog
dog.fleas    =>  method_missing!     # hunh?

# but this works again
dog = Dog.find_by_id(dog.id)
dog.fleas   =>  []

Is there some AR magic that gets broken by using a variable class name?

Thanks!

- Isaac
This topic is locked and can not be replied to.