From 358360198e623229495b7175a2b3a0fe96a543ac Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Mon, 18 Sep 2017 04:29:49 +0900 Subject: 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. --- activerecord/lib/active_record/persistence.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/persistence.rb') 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 -- cgit v1.2.3