私は親文書を持っていて、2つの異なるタイプの埋め込み文書を持ちたいと思っています.1つは親として、もう1つはオプションの親を持つ子としてです。例:この例ではMongoid:埋め込みドキュメント間の関係を実装する方法は?
class ParentDoc
include Mongoid::Document
embeds_many :special_docs
embeds_many :special_doc_groupings
end
class SpecialDoc
include Mongoid::Document
embedded_in :parent_doc
belongs_to :special_doc_groupings
end
class SpecialDocGrouping
include Mongoid::Document
embedded_in :parent_doc
has_many :special_docs
end
、SpecialDocsとSpecialDocGroupingsは関係なしに存在することができ、または必要に応じて親子関係を有することができます。
我々はこのエラーを取得しているためしかし、これは無効Mongoid団体です:私はそれがだという事実以外に、私が作成しようとしている関連の種類に何か問題が表示されていない
Mongoid::Errors::MixedRelations:
Problem: Referencing a(n) SpecialDoc document from the SpecialDocGrouping document via a relational association is not allowed since the SpecialDoc is embedded.
Summary: In order to properly access a(n) SpecialDoc from SpecialDocGrouping the reference would need to go through the root document of SpecialDoc. In a simple case this would require Mongoid to store an extra foreign key for the root, in more complex cases where SpecialDoc is multiple levels deep a key would need to be stored for each parent up the hierarchy.
Resolution: Consider not embedding SpecialDoc, or do the key storage and access in a custom manner in the application code.
モンゴイドによってサポートされていません。
このタイプの関連付けを自分で実装するにはどうすればよいですか?
YAA、あなたの質問に関してmongoidに関連のようなタイプを定義傾けるあなたの権利は '私は自分自身を協会のこのタイプを実装する(コードがテストされていない)?'も聞いたことがある[拡大] (http://guides.rubyonrails.org/association_basics.html#extend)でactiverecord associationをうまく実装できますかmongoidでもそのようなものをサポートしていれば拡張を使用できます(私はチェックしてabtを知らせます)乾杯。 – Viren