I have problem with rails relations. I have base model ant his inherited version
class User < ActiveRecord::Base
end
class Admin < User
end
Next I have membership model with polymorphic association
class Membership < ActiveRecord::Base
belongs_to :group
belongs_to :membershipable, polymorphic: true
end
When I tryied to make new instance of Membership model, by typing for example
Membership.new group: Group.first, membershipable: Admin.first
membershipable_type is setting to "User" instead of "Admin". So i create before_validation callback
def proper_sti_type
self.membershipable_type = memebrshipable.class.name
end
and it works, but i guess is better way to do this. Maybe someone know the better solution?
Thanks
Tom