Rails 和 mongoid:RC7 和嵌入式文档发生了什么?
到目前为止我一直在使用 rc6,我决定升级,但这完全是 破坏我的应用程序?也许我做错了什么,但我相信我 遵循文档。
我有一个嵌入许多 Localized_Content 的模型内容。 一旦我创建了内容并想要添加本地化内容,
我将执行以下操作:
@content = Content.find('xxx')
@new_content = @content.localized_contants.build()
@new_content.save
这在 rc6 下工作得非常好,并且正确更新了所有 localized_contant 中的时间戳(使用 include Mongoid::Timestamps) 但是在 rc7 中做同样的事情会出现以下错误: “不允许访问 LocalizedContent 集合,因为它 是嵌入文档,请从根访问集合 文档。”
好吧,也许我需要直接从父内容保存然后就可以了。 做一个
@content.save
工作但不会触发所有时间戳 这打破了我的应用程序的逻辑......我应该做什么?
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::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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@content.save
是正确的选择。您应该重构代码以在父对象而不是嵌入文档上调用save()
。@content.save
is the way to go. You should refactor your code to callsave()
on the parent object instead of the embedded document.