Sha256: e17a41d8ecbf16406d6baa794c699429cce2bca8e5ef0a002740b465b0af5c59

Contents?: true

Size: 842 Bytes

Versions: 1

Compression:

Stored size: 842 Bytes

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Commands
    class DestroyAll
      # Performs a destroy of the all the +Documents+ that match the criteria
      # supplied. Will execute all the destroy callbacks for each +Document+.
      #
      # Options:
      #
      # params: A set of conditions to find the +Documents+ by.
      # klass: The class of the +Document+ to execute the find on.
      #
      # Example:
      #
      # <tt>DestroyAll.execute(Person, :conditions => { :field => "value" })</tt>
      def self.execute(klass, params)
        conditions = params[:conditions] || {}
        params[:conditions] = conditions.merge(:_type => klass.name)
        documents = klass.find(:all, params)
        matching = documents.count
        documents.each { |doc| Destroy.execute(doc) }; matching
      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/destroy_all.rb