Methods

Class/Module Index [+]

Quicksearch

Mongoid::Persistence::Insertion

Contains common logic for insertion operations.

Public Instance Methods

prepare(&block) click to toggle source

Wrap all the common insertion logic for both root and embedded documents and then yield to the block.

@example Execute common insertion logic.

prepare do |doc|
  collection.insert({ :field => "value })
end

@param [ Proc ] block The block to call.

@return [ Document ] The inserted document.

@since 2.1.0

# File lib/mongoid/persistence/insertion.rb, line 20
def prepare(&block)
  document.tap do |doc|
    unless validating? && document.invalid?(:create)
      result = doc.run_callbacks(:save) do
        doc.run_callbacks(:create) do
          yield(doc)
          doc.new_record = false
          doc.reset_persisted_children and true
        end
      end

      unless result == false
        doc.move_changes
        Threaded.clear_options!
      end
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.