开发者

Rails and mongoid: What is going on with RC7 and embedded documents?

开发者 https://www.devze.com 2023-02-11 23:48 出处:网络
Until now I was using rc6 and I decided to upgrade, but it\'s totally breaking my app ? Maybe I am doing something wrong, but I believe I

Until now I was using rc6 and I decided to upgrade, but it's totally breaking my app ? Maybe I am doing something wrong, but I believe I followed the documentation.

I have a model Content that embeds_many Localized_Content. Once I have a content created and wanted to added a localized content

I would do the following:

 @content = Content.find('xxx')
 @new_content = @content.localized_contants.build()
 @new_content.save 

This is working perfectly fine under rc6 and updates correctly all the timestamps in localized_contant (using include Mongoid开发者_JS百科::Timestamps) But doing the same thing in rc7 break with the following error: "Access to the collection for LocalizedContent is not allowed since it is an embedded document, please access a collection from the root document."

Ok, maybe I need to save directly from the parent content then ok. Doing a

@content.save

works but will not trigger all the timestamping and this breaks the logic of my apps... what should I do ?


@content.save is the way to go. You should refactor your code to call save() on the parent object instead of the embedded document.

0

精彩评论

暂无评论...
验证码 换一张
取 消