0
私のプロジェクトをmysqlからmongodbに移行していくつかの問題があります。mongoidの埋め込みドキュメントを更新する最良の方法
埋め込みドキュメントの属性をActiveRecordの方法で更新するにはどうすればよいですか?モンゴイドで可能ですか?例えば
class Template
include Mongoid::Document
include Mongoid::Versioning
embedded_in :site, :inverse_of => :templates
end
class Site
embeds_many :templates
end
:
Access to the collection for Template is not allowed since it is an embedded document, please access a collection from the root document.
[OK]を、しかし、ルート文書からそれを行う方法:
site = Site.find(params[:current_site_id])
template = site.templates.find(params[:id])
template.update_attributes(params[:template])
私が得ましたか。
編集:
それは私はいくつかのトラブルを作るテンプレートで使用Mongoid ::バージョンのように見えます。私は含まれているモジュールを削除し、すべて正常に動作します。
あなたはどのバージョンのモンゴイダルをお使いですか? –
gem 'mongoid'、 '2.0.0' –
テンプレートは埋め込まれたドキュメントなので、 'Mongoid :: Versioning'を' Site'モデルに追加すると、埋め込まれたドキュメントへの変更が反映されます。埋め込まれたドキュメントは実際には親ドキュメントの一部であり、リレーションではないからです。 – theTRON