MongoDB MongoDB 不支持 polymorphic => true?

metal · February 17, 2012 · Last by metal replied at February 18, 2012 · 2730 hits

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

#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

You need to Sign in before reply, if you don't have an account, please Sign up first.