ITeye博客

Rails polymorphic的使用和理解

夜鸣猪 · 2012-09-07 02:03 · Ruby On Rails · 编程语言 · Markdown

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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。