我有 3 个模型:
class Interest
include Mongoid::Document
has_many :user_hobby
end
class UserHobby
include Mongoid::Document
field :contacts, :type => Array
belongs_to :interest, :foreign_key => "interest", inverse_of: nil
belongs_to :interest, :foreign_key => "related_interests", inverse_of: nil
embedded_in :user
end
class User
include Mongoid::Document
embeds_many :user_hobby
end
我必须添加 user 和 user_hobby 之间的嵌入关系,但之后(在我的测试中)当我想保存兴趣时出现此错误:
Mongoid::Errors::MixedRelations: 由于嵌入了 UserHobby,因此不允许通过关系关联从兴趣文档中引用 (n) UserHobby 文档。
我看了这个话题,但也没有帮助我Mongoid::Errors::MixedRelations
谢谢。