Method: Mongoid::Persistence::Operations::Embedded::Remove#persist

Defined in:
lib/mongoid/persistence/operations/embedded/remove.rb

#persisttrue

Remove the document from the database. If the parent is a new record, it will get removed in Ruby only. If the parent is not a new record then either an $unset or $set will occur, depending if it’s an embeds_one or embeds_many.

Examples:

Remove an embedded document.

RemoveEmbedded.persist

Returns:

  • (true)

    Always true.



28
29
30
31
32
33
34
35
# File 'lib/mongoid/persistence/operations/embedded/remove.rb', line 28

def persist
  prepare do |doc|
    parent.remove_child(doc) if notifying_parent?
    if parent.persisted?
      collection.update(parent.atomic_selector, deletes, options)
    end
  end
end