我有一个嵌入了许多“SuggestedPerson”的模型“Person”。SuggestedPerson 还引用另一个人(被建议的人)。所以 Person 需要 embed_many 和 has_many SuggestedPerson。问题是 Mongo 返回错误:
失败/错误:Mongoid::Errors::MixedRelations:
Problem: Referencing a(n) SuggestedPerson document from the Person document via a relational association is not allowed since the
SuggestedPerson 被嵌入。
代码:
class Person
embeds_many :suggested_persons, :class_name => "SuggestedPerson", :inverse_of => :person
has_many :suggested_to_persons, :class_name => "SuggestedPerson", :inverse_of => :to_person
end
class SuggestedPerson
embedded_in :person, :class_name => "Person", :inverse_of => :suggested_persons
belongs_to :to_person, :class_name => "Person", :inverse_of => :suggested_to_persons
end
有没有解决的办法?