MongoDB MongoDB 不支持 polymorphic => true?

metal · 2012年02月17日 · 最后由 metal 回复于 2012年02月18日 · 2730 次阅读

不能这样进行关联。是吗?

#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

需要 登录 后方可回复, 如果你还没有账号请 注册新账号