不能这样进行关联。是吗?
支持,see https://github.com/huacnlee/ruby-china/blob/master/app/models/comment.rb
#1 楼 @huobazi 我高了半天没成功。
#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
#3 楼 @willmouse 3Q