#2 楼 @metal
class Company
include Mongoid::Document
has_many :posts, as: :postable
end
class Person
include Mongoid::Document
has_many :posts, as: :postable
end
class Post
include Mongoid::Document
belongs_to :postable, polymorphic: true
end
mongoid.org 上的代码,poly 还需要一个表示能力的文档,不过是虚的,一般叫 xxxxable
children 标示为:polymorphic => true
parent 用:as => xxxxable