2012-02-07 18 views
1

是否有任何簡單的方法可以使has_and_belongs_to_many與其他類的嵌入式模型中的外鍵一起工作?Mongoid:has_many與嵌入式文檔中的外鍵

我的使用情況是:

class Account 
    include Mongoid::Document 
    has_and_belongs_to_many :users 
end 

class User 
    include Mongoid::Document 
    embeds_many :memberships 
end 

class Membership 
    include Mongoid::Document 
    belongs_to :account, autosave: true 
    embedded_in :user 
end 

的想法是,會員制模式還包括與成員的其它數據,如角色。

但是,即使在數據庫中用戶有多個外鍵(在嵌入式成員資格中),帳戶中的has_and_belongs_to_many也不會選擇這些用戶。

回答

0

我相信MongoDB/Mongoid不支持通過關係關聯直接訪問嵌入字段。