From b901a49473817339e892f6c237a365a361b0b2d7 Mon Sep 17 00:00:00 2001 From: Ted Johansson Date: Thu, 15 Oct 2015 17:00:28 +0800 Subject: Add deprecation warning to `ActiveRecord::Relation#update` When passing an instance of `ActiveRecord::Base` to `#update`, it would internally call `#find`, resulting in a misleading deprecation warning. This change gives this deprecated use of `#update` its own, meaningful warning. --- activerecord/lib/active_record/relation.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 05bf87ab9d..392b462aa9 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -417,6 +417,13 @@ module ActiveRecord elsif id == :all to_a.each { |record| record.update(attributes) } else + if ActiveRecord::Base === id + id = id.id + ActiveSupport::Deprecation.warn(<<-MSG.squish) + You are passing an instance of ActiveRecord::Base to `update`. + Please pass the id of the object by calling `.id` + MSG + end object = find(id) object.update(attributes) object -- cgit v1.2.3