0

我有一个以下协会

Class Person 
    include Mongoid::Document
    embeds_many :employments
end

Class Employment
    include Mongoid::Document
    references_many :centres
end

class Centre
    include Mongoid::Document
    referenced_in :employment
end

现在当我尝试

Person.first.employments.first.centres.build它给了我这样的错误

NoMethodError: undefined method `centres' for #<Employment:0x000001023f38f8>

我做错什么了吗?

或者嵌入的文档不能引用许多其他文档?

4

2 回答 2

1

大佬,你设置错了 嵌入文档不能引用其他模型。如果您仍想使用嵌入文档引用另一个模型,则必须创建自定义函数。

于 2011-03-24T11:30:45.400 回答
0

尝试:

class Centre
  include Mongoid::Document
  referenced_in :employment, :inverse_of => :centres
end
于 2010-11-22T04:39:46.147 回答