9
我正在用mongoid构建我的第一个应用程序,并且在删除嵌入的资源时遇到问题。我有这些模型:用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>]
调用销毁删除评论(或删除)上嵌入式文档似乎将其删除在内存中,而不是从数据库中删除。任何有识之士将非常感谢!
嗨。你有没有找到答案?真的很感谢任何帮助 – Ben
抱歉 - 不 - 这是一段时间以前,我没有追求的项目 – chrispanda