2010-10-01 57 views
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> 

錯誤我在做任何事情錯了嗎?

或者嵌入式文件不能引用許多其他文件?

回答

1

老兄,你的設置是錯誤的。嵌入式文檔不能引用其他模型。如果你仍然想引用另一個嵌入式文檔模型,那麼你將不得不創建自定義函數。

0

嘗試:

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