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
精彩评论