【发布时间】:2011-11-02 08:01:43
【问题描述】:
我正在使用 mongoid 构建我的第一个应用,但在删除嵌入式资源时遇到了问题。我有这些模型:
class Article
include Mongoid::Document
field :body
embeds_many :comments
等等。
class Comment
include Mongoid::Document
field :body
embedded_in :article, :inverse_of => :comments
end
我不明白为什么我不能从文章中删除评论
ruby-1.9.2-p290 :043 > @article.comments
=> [#<Comment _id: 4eb0e991a27d201ded000038, _type: nil, body: "foo", score: nil>]
ruby-1.9.2-p290 :045 > @article.comments.first.destroy
=> true
ruby-1.9.2-p290 :046 > @article.comments
=> []
ruby-1.9.2-p290 :047 > @article.save
=> true
ruby-1.9.2-p290 :049 > @article.reload
=> #<Article _id: 4eb0e991a27d201ded000037, _type: nil, body: "foo", title: ....
ruby-1.9.2-p290 :050 > @article.comments
=> [#<Comment _id: 4eb0e991a27d201ded000038, _type: nil, body: "foo", score: nil>]
对嵌入文档调用destroy(或delete)似乎会将其从内存中删除,而不是从数据库中删除。任何见解将不胜感激!
【问题讨论】:
-
嗨。你找到答案了吗?非常感谢任何帮助
-
抱歉 - 不 - 这是不久前的事了,我还没有从事这个项目
标签: ruby-on-rails mongoid