From 13989ff8c690b9b9e5282bd4098666c909ea64d3 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Tue, 29 Dec 2009 11:45:25 +0530 Subject: Use relation#delete_all for Model.delete_all --- activerecord/lib/active_record/base.rb | 6 +----- activerecord/lib/active_record/relation.rb | 3 +-- 2 files changed, 2 insertions(+), 7 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 53f0a920a3..6715871bf9 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -939,11 +939,7 @@ module ActiveRecord #:nodoc: # Both calls delete the affected posts all at once with a single DELETE statement. If you need to destroy dependent # associations or call your before_* or +after_destroy+ callbacks, use the +destroy_all+ method instead. def delete_all(conditions = nil) - if conditions - arel_table.where(Arel::SqlLiteral.new(construct_conditions(conditions, scope(:find)))).delete - else - arel_table.delete - end + arel_table.where(construct_conditions(conditions, scope(:find))).delete_all end # Returns the result of an SQL statement that should only include a COUNT(*) in the SELECT part. diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index a3d7be3afe..c6c63291c9 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -225,8 +225,7 @@ module ActiveRecord end def delete_all - @relation.delete - reset + @relation.delete.tap { reset } end def loaded? -- cgit v1.2.3