您的位置:首页 > 大数据 > 人工智能

Rails 多态

2016-03-24 00:00 423 查看
class Person < ActiveRecord::Base
has_one :address, :as => :addressable
end

class Company < ActiveRecord::Base
has_one :address, :as => :addressable
end

class Address < ActiveRecord::Base
belongs_to :addressable, :polymorphic => true
end

Address 有adressable_id addressable_type其中,addressable_type可以为Company或者Person
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  polymorphic