我有一個模型「人」embeds_many「SuggestedPerson」s。 SuggestedPerson還引用了另一個人(被推薦的人)。所以Person需要embed_many和has_many SuggestedPerson。問題是蒙戈返回錯誤:Mongoid embeds_many和has_many到相同的模型
Failure/Error: Mongoid::Errors::MixedRelations:
Problem: Referencing a(n) SuggestedPerson document from the Person document via a relational association is not allowed since the
SuggestedPerson is embedded.
代碼:
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
有沒有辦法解決?
最快的方法是將關聯更改爲has_many,但這很不方便。 – freemanoid 2013-03-05 09:05:55
是的,謝謝,那差不多是我所做的:/ – LMH 2013-03-05 14:57:41
但我也想知道另一個解決方案沒有破解... – freemanoid 2013-03-06 07:27:20