Skip to content

Commit

Permalink
delete_all and destroy_all
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis Reeder committed Dec 16, 2010
1 parent cad6152 commit ecc2a9f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
14 changes: 13 additions & 1 deletion README.markdown
Expand Up @@ -236,12 +236,24 @@ or

o.something_id = x

### Batch Save
## Batch Save

To do a batch save using SimpleDB's batch saving feature to improve performance, simply create your objects, add them to an array, then call:

MyClass.batch_save(object_list)

## Batch Delete

To do a batch save using SimpleDB's batch saving feature to improve performance, simply create your objects, add them to an array, then call:

MyClass.batch_delete(object_list or list of ids)

## Operations across a Query

MyClass.delete_all(find_options)
MyClass.destroy_all(find_options)


## Caching

You can use any cache that supports the ActiveSupport::Cache::Store interface.
Expand Down
10 changes: 6 additions & 4 deletions lib/simple_record.rb
Expand Up @@ -646,9 +646,10 @@ def self.delete(id)
connection.delete_attributes(domain, id)
end

def self.delete_all(*params)
# Pass in the same OPTIONS you'd pass into a find(:all, OPTIONS)
def self.delete_all(options)
# could make this quicker by just getting item_names and deleting attributes rather than creating objects
obs = self.find(params)
obs = self.find(:all, options)
i = 0
obs.each do |a|
a.delete
Expand All @@ -657,8 +658,9 @@ def self.delete_all(*params)
return i
end

def self.destroy_all(*params)
obs = self.find(params)
# Pass in the same OPTIONS you'd pass into a find(:all, OPTIONS)
def self.destroy_all(options)
obs = self.find(:all, options)
i = 0
obs.each do |a|
a.destroy
Expand Down

0 comments on commit ecc2a9f

Please sign in to comment.