meow
meow

Reputation: 28164

"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?

Upvotes: 1

Views: 3180

Answers (1)

Tilo
Tilo

Reputation: 33732

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

Upvotes: 2

Related Questions