Sha256: e99af967d826d0c4e70a4bf50753bb095cf8681a679b6fa6cd902cf670522fef

Contents?: true

Size: 1.29 KB

Versions: 188

Compression:

Stored size: 1.29 KB

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Persistence #:nodoc:
    module Operations #:nodoc:
      module Embedded #:nodoc:

        # Insert is a persistence command responsible for taking a document that
        # has not been saved to the database and saving it. This specific class
        # handles the case when the document is embedded in another.
        #
        # The underlying query resembles the following MongoDB query:
        #
        #   collection.update(
        #     { "_id" : 1 },
        #     { "$push" : { "field" : "value" } },
        #     false
        #   );
        class Insert
          include Insertion, Operations

          # Insert the new document in the database. If the document's parent is a
          # new record, we will call save on the parent, otherwise we will $push
          # the document onto the parent.
          #
          # @example Insert an embedded document.
          #   Insert.persist
          #
          # @return [ Document ] The document to be inserted.
          def persist
            prepare do
              if parent.new?
                parent.insert
              else
                collection.update(parent.atomic_selector, inserts, options)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

188 entries across 96 versions & 4 rubygems

Version Path
classiccms-0.6.4 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/operations/embedded/insert.rb
classiccms-0.6.4 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/operations/embedded/insert.rb
classiccms-0.6.4 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/operations/embedded/insert.rb
classiccms-0.6.3 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/operations/embedded/insert.rb
classiccms-0.6.3 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/operations/embedded/insert.rb
classiccms-0.6.3 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/operations/embedded/insert.rb
classiccms-0.6.2 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/operations/embedded/insert.rb
classiccms-0.6.2 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/operations/embedded/insert.rb
classiccms-0.6.2 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/operations/embedded/insert.rb
classiccms-0.6.1 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/operations/embedded/insert.rb
classiccms-0.6.1 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/operations/embedded/insert.rb
classiccms-0.6.1 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/operations/embedded/insert.rb
classiccms-0.6.0 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/operations/embedded/insert.rb
classiccms-0.6.0 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/operations/embedded/insert.rb
classiccms-0.6.0 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/operations/embedded/insert.rb
classiccms-0.5.17 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/persistence/operations/embedded/insert.rb
classiccms-0.5.17 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/operations/embedded/insert.rb
classiccms-0.5.17 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/operations/embedded/insert.rb
classiccms-0.5.16 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/persistence/operations/embedded/insert.rb
classiccms-0.5.16 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/persistence/operations/embedded/insert.rb