"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
精彩评论