aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/persistence.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-09-18 04:29:49 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-09-18 08:12:59 +0900
commit358360198e623229495b7175a2b3a0fe96a543ac (patch)
treeb5d093cd2390b97c326f6f166e13d9d5eb845ccc /activerecord/lib/active_record/persistence.rb
parent9ac7dd47c5e847f7dbfb8d527ee2b917fa9fcd38 (diff)
downloadrails-358360198e623229495b7175a2b3a0fe96a543ac.tar.gz
rails-358360198e623229495b7175a2b3a0fe96a543ac.tar.bz2
rails-358360198e623229495b7175a2b3a0fe96a543ac.zip
Ensure returning affected objects for class level `update` and `destroy`
Class level `update` and `destroy` are using `find` in the internal, so it will raise `RecordNotFound` if given ids cannot find an object even though the method already affect (update or destroy) to any objects. These methods should return affected objects even in that case.
Diffstat (limited to 'activerecord/lib/active_record/persistence.rb')
-rw-r--r--activerecord/lib/active_record/persistence.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index 4a5ccdc597..d1cb3783e7 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -99,7 +99,7 @@ module ActiveRecord
# for updating all records in a single query.
def update(id = :all, attributes)
if id.is_a?(Array)
- id.map.with_index { |one_id, idx| update(one_id, attributes[idx]) }
+ id.map.with_index { |one_id, idx| update(one_id, attributes[idx]) }.compact
elsif id == :all
all.each { |record| record.update(attributes) }
else
@@ -112,6 +112,7 @@ module ActiveRecord
object.update(attributes)
object
end
+ rescue RecordNotFound
end
# Destroy an object (or multiple objects) that has the given id. The object is instantiated first,
@@ -135,10 +136,11 @@ module ActiveRecord
# Todo.destroy(todos)
def destroy(id)
if id.is_a?(Array)
- id.map { |one_id| destroy(one_id) }
+ id.map { |one_id| destroy(one_id) }.compact
else
find(id).destroy
end
+ rescue RecordNotFound
end
# Deletes the row with a primary key matching the +id+ argument, using a