Sha256: 26d6fdd5aa6f4d069a4c15f1b8760ca299a0ffdd4a6f6b25158a40f7df1a495a

Contents?: true

Size: 860 Bytes

Versions: 1

Compression:

Stored size: 860 Bytes

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Commands
    class Save
      # Performs a save of the supplied +Document+, handling all associated
      # callbacks and validation.
      #
      # Options:
      #
      # doc: A +Document+ that is going to be persisted.
      #
      # Returns: +true+ if validation passes, +false+ if not.
      def self.execute(doc, validate = true)
        return false if validate && !doc.valid?
        doc.run_callbacks :save do
          parent = doc._parent
          doc.new_record = false
          saved = if parent
            Save.execute(parent, validate)
          else
            doc.collection.save(doc.raw_attributes, :safe => Mongoid.persist_in_safe_mode)
          end
          doc.move_changes if saved
          return false unless saved
        end
        return true
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongoid-pre-2.0.0.beta1 lib/mongoid/commands/save.rb