属于准 STI 对象的多态对象:object_type 不正确
考虑一下:
class Person < ActiveRecord::Base
class << self
def setup
has_one :address, :as => :addressable
end
end
end
class Employee < Person
setup
end
class Address < ActiveRecord::Base
belongs_to :addressable, :polymorphic => true
end
# Shouldn't this be 'Employee'? Is it possible to override?
Employee.create.address.create.addressable_type == 'Person'
编辑:我有一段时间感到困惑。这并不是真正的 STI,它只是继承,因为 Employee
有自己的表。
谢谢!
Consider:
class Person < ActiveRecord::Base
class << self
def setup
has_one :address, :as => :addressable
end
end
end
class Employee < Person
setup
end
class Address < ActiveRecord::Base
belongs_to :addressable, :polymorphic => true
end
# Shouldn't this be 'Employee'? Is it possible to override?
Employee.create.address.create.addressable_type == 'Person'
Edit: I got confused for a while there. This is not really STI, it's just inheritance, as Employee
has its own table.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
宾果:
Bingo: