开发者

"Cascade deleting" in mongoid

For example

User
  references_many :answers

Answer
  references_many :users

Say we are deleting answers for a given user, how do we do it such that both the references on the user开发者_高级运维/answer objects are deleted?


Cascading Removals

Similar to ActiveRecord, if you want child relational associations to be deleted when the parent record is deleted, simply supply the :dependent option on the references_one or references_many macro.

class User
  include Mongoid::Document
  references_one :profile, :dependent => :destroy
  references_many :answers, :dependent => :delete
end
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜