Skip to content

Commit

Permalink
Merge pull request #6089 from frodsan/delete_all_limit
Browse files Browse the repository at this point in the history
delete_all raise an error if a limit is provided - fixes #4979
  • Loading branch information
tenderlove committed May 1, 2012
2 parents b2a24a1 + 2f68125 commit 7d2df5f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions activerecord/lib/active_record/relation.rb
Expand Up @@ -390,6 +390,8 @@ def destroy(id)
# If you need to destroy dependent associations or call your <tt>before_*</tt> or
# +after_destroy+ callbacks, use the +destroy_all+ method instead.
def delete_all(conditions = nil)
raise ActiveRecordError.new("delete_all doesn't support limit scope") if self.limit_value

if conditions
where(conditions).delete_all
else
Expand Down
4 changes: 4 additions & 0 deletions activerecord/test/cases/relations_test.rb
Expand Up @@ -688,6 +688,10 @@ def test_delete_all_loaded
assert davids.loaded?
end

def test_delete_all_limit_error
assert_raises(ActiveRecord::ActiveRecordError) { Author.limit(10).delete_all }
end

def test_select_argument_error
assert_raises(ArgumentError) { Developer.select }
end
Expand Down

0 comments on commit 7d2df5f

Please sign in to comment.