开发者

about embedded document referencing many other documents

I have a following association

Class Person 
    include Mongoid::Document
    embeds_m开发者_如何学运维any :employments
end

Class Employment
    include Mongoid::Document
    references_many :centres
end

class Centre
    include Mongoid::Document
    referenced_in :employment
end

Now when I tried

Person.first.employments.first.centres.build it gave me errors like

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

Am i doing any thing wrong?

Or the embedded document cannot reference many other documents?


Dude, you setup is wrong. Embedded document cannot reference other model. If you still want to reference another model with embedded document, then you will have to create custom function.


Try:

class Centre
  include Mongoid::Document
  referenced_in :employment, :inverse_of => :centres
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜