Sha256: 14609ecdd972250f36a303aa09bfc97b54f77ca19a837bd95ae559ba0c81493d

Contents?: true

Size: 773 Bytes

Versions: 9

Compression:

Stored size: 773 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)
        klass.find(:all, params).each { |doc| Destroy.execute(doc) }; true
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mongoid-2.0.0.alpha lib/mongoid/commands/destroy_all.rb
mongoid-1.2.14 lib/mongoid/commands/destroy_all.rb
mongoid-1.2.13 lib/mongoid/commands/destroy_all.rb
mongoid-1.2.12 lib/mongoid/commands/destroy_all.rb
mongoid-1.2.11 lib/mongoid/commands/destroy_all.rb
mongoid-1.2.10 lib/mongoid/commands/destroy_all.rb
mongoid-1.2.9 lib/mongoid/commands/destroy_all.rb
mongoid-1.2.8 lib/mongoid/commands/destroy_all.rb
mongoid-1.2.7 lib/mongoid/commands/destroy_all.rb