Sha256: 3431a61ada5fc4780cb3bcb1f39a0e765a0b9387f4e6f988645c4d8b1c6325eb
Contents?: true
Size: 1.08 KB
Versions: 163
Compression:
Stored size: 1.08 KB
Contents
# encoding: utf-8 module Mongoid #:nodoc: module Persistence #:nodoc: # Contains common logic for insertion operations. module Insertion # 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 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 true end end unless result == false doc.reset_persisted_children doc.move_changes Threaded.clear_options! end end end end end end end
Version data entries
163 entries across 71 versions & 3 rubygems