Sha256: a089de18774ace22e4fe28304547053b1846aee5f953b5d9c48f27a69e96500c

Contents?: true

Size: 809 Bytes

Versions: 19

Compression:

Stored size: 809 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 :before_save
        parent = doc._parent
        if parent ? Save.execute(parent, validate) : doc.collection.save(doc.raw_attributes, :safe => Mongoid.persist_in_safe_mode)
          doc.new_record = false
          doc.run_callbacks :after_save
          return true
        else
          return false
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
mongoid-1.2.14 lib/mongoid/commands/save.rb
mongoid-1.2.13 lib/mongoid/commands/save.rb
mongoid-1.2.12 lib/mongoid/commands/save.rb
mongoid-1.2.11 lib/mongoid/commands/save.rb
mongoid-1.2.10 lib/mongoid/commands/save.rb
mongoid-1.2.9 lib/mongoid/commands/save.rb
mongoid-1.2.8 lib/mongoid/commands/save.rb
mongoid-1.2.7 lib/mongoid/commands/save.rb
mongoid-1.2.6 lib/mongoid/commands/save.rb
mongoid-1.2.5 lib/mongoid/commands/save.rb
mongoid-1.2.4 lib/mongoid/commands/save.rb
mongoid-1.2.3 lib/mongoid/commands/save.rb
mongoid-1.2.2 lib/mongoid/commands/save.rb
mongoid-1.2.1 lib/mongoid/commands/save.rb
mongoid-1.2.0 lib/mongoid/commands/save.rb
mongoid-1.1.4 lib/mongoid/commands/save.rb
mongoid-1.1.3 lib/mongoid/commands/save.rb
mongoid-1.1.2 lib/mongoid/commands/save.rb
mongoid-1.1.1 lib/mongoid/commands/save.rb