Skip to content

Commit

Permalink
early return on delete and destroy methods
Browse files Browse the repository at this point in the history
When delete or destroy is called on all records nothing
is deleted or destroyed. Intead of running through the code and still
not deleteing anything, we should early return
  • Loading branch information
eileencodes committed May 18, 2014
1 parent dbbcc83 commit 540262a
Showing 1 changed file with 2 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def count(column_name = nil, count_options = {})
# are actually removed from the database, that depends precisely on
# +delete_records+. They are in any case removed from the collection.
def delete(*records)
return if records.empty?
_options = records.extract_options!
dependent = _options[:dependent] || options[:dependent]

Expand All @@ -257,6 +258,7 @@ def delete(*records)
# Note that this method removes records from the database ignoring the
# +:dependent+ option.
def destroy(*records)
return if records.empty?
records = find(records) if records.any? { |record| record.kind_of?(Fixnum) || record.kind_of?(String) }
delete_or_destroy(records, :destroy)
end
Expand Down

0 comments on commit 540262a

Please sign in to comment.