Sha256: c368dd011858d4b66398dff20a2f5ea78285cd53a2b9ed749e8cd75544473c60
Contents?: true
Size: 1.37 KB
Versions: 11
Compression:
Stored size: 1.37 KB
Contents
# encoding: utf-8 module Mongoid #:nodoc: module Persistence #:nodoc: # Remove is a persistence command responsible for deleting a document from # the database. # # The underlying query resembles the following MongoDB query: # # collection.remove( # { "_id" : 1 }, # false # ); class RemoveEmbedded < Command # 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. # # Example: # # <tt>RemoveEmbedded.persist</tt> # # Returns: # # +true+ or +false+, depending on if the removal passed. def persist parent = @document._parent parent.remove(@document) unless parent.new_record? update = { @document._remover => removal_selector } @collection.update(parent._selector, update, @options.merge(:multi => false)) end; true end protected # Get the value to pass to the removal modifier. def setter @document._index ? @document.id : true end def removal_selector @document._index ? { @document._pull => { "_id" => @document.id } } : { @document._path => setter } end end end end
Version data entries
11 entries across 11 versions & 1 rubygems