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