aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2017-02-11 17:46:28 -0500
committerSean Griffin <sean@seantheprogrammer.com>2017-02-11 17:46:28 -0500
commit4fed08fa787a316fa51f14baca9eae11913f5050 (patch)
treeb755a21b5cb56158bcababc26ce97b00b6332d35 /activerecord/lib/active_record/attribute_methods
parenteb4aba0052a0a51d26ec31640fc833e3848dc9e8 (diff)
downloadrails-4fed08fa787a316fa51f14baca9eae11913f5050.tar.gz
rails-4fed08fa787a316fa51f14baca9eae11913f5050.tar.bz2
rails-4fed08fa787a316fa51f14baca9eae11913f5050.zip
Deprecate calling `attr_will_change!` with non-attributes
This was never really intended to work (at least not without calling `define_attribute_methods`, which is less common with Active Record). As we move forward the intention is to require the use of `attribute` over `attr_accessor` for more complex model behavior both on Active Record and Active Model, so this behavior is deprecated. Fixes #27956. Close #27963. [Alex Serban & Sean Griffin]
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods')
-rw-r--r--activerecord/lib/active_record/attribute_methods/dirty.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/dirty.rb b/activerecord/lib/active_record/attribute_methods/dirty.rb
index b0e1391cb9..31c1e687dc 100644
--- a/activerecord/lib/active_record/attribute_methods/dirty.rb
+++ b/activerecord/lib/active_record/attribute_methods/dirty.rb
@@ -275,7 +275,17 @@ module ActiveRecord
def attribute_will_change!(attr_name)
super
- mutations_from_database.force_change(attr_name)
+ if self.class.has_attribute?(attr_name)
+ mutations_from_database.force_change(attr_name)
+ else
+ ActiveSupport::Deprecation.warn(<<-EOW.squish)
+ #{attr_name} is not an attribute known to Active Record.
+ This behavior is deprecated and will be removed in the next
+ version of Rails. If you'd like #{attr_name} to be managed
+ by Active Record, add `attribute :#{attr_name} to your class.
+ EOW
+ mutations_from_database.deprecated_force_change(attr_name)
+ end
end
def _update_record(*)