Running into an interesting problem that at first glance appears to be a
bug in the AR association code. However, it’s explicitly coded this way
so I’m not so sure.
I have some code like this:
class Address < ActiveRecord::Base
belongs_to :addressable, :polymorphic => true
class Person < ActiveRecord::Base
has_many :addresses, :as => :addressable, :dependent => :destroy
class Member < Person
Adding an Address to a Member results in the addressable_type column
equaling “Person” when it should be “Member”. Looking in
and ActiveRecord::Associations:: HasManyAssociation#construct_sql it’s
Removing the call to base_class results in the behavior I expected. I
did this by patching the two classes at runtime from a file in lib/.
I guess my question is, are my expectations wrong here or is this a bug?
The inclusion of base_class strikes me as something someone meant to do.