Sha256: 08081be1e843f5fa2605e2d3ba742c19f442010e392de25c415cffc17ec2322e

Contents?: true

Size: 966 Bytes

Versions: 5

Compression:

Stored size: 966 Bytes

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Persistence #:nodoc:
    # Remove is a persistence command responsible for deleting a document from
    # the database.
    #
    # The underlying query resembles the following MongoDB query:
    #
    #   collection.remove(
    #     { "field" : value },
    #     false
    #   );
    class RemoveAll < Command
      # Remove the document from the database: delegates to the MongoDB
      # collection remove method.
      #
      # Example:
      #
      # <tt>Remove.persist</tt>
      #
      # Returns:
      #
      # +true+ if success, +false+ if not.
      def persist
        remove
      end

      protected
      # Remove the document from the database.
      def remove
        selector = (@klass.hereditary? ? @selector.merge(:_type => @klass.name) : @selector)
        count = @collection.find(selector).count
        @collection.remove(selector, @options)
        count
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mongoid-2.0.0.beta.20 lib/mongoid/persistence/remove_all.rb
mongoid-2.0.0.beta.19 lib/mongoid/persistence/remove_all.rb
mongoid-2.0.0.beta.18 lib/mongoid/persistence/remove_all.rb
mongoid-2.0.0.beta.17 lib/mongoid/persistence/remove_all.rb
mongoid-2.0.0.beta.16 lib/mongoid/persistence/remove_all.rb