From 72e63c71bb3f73870e280964def25b7578818b1b Mon Sep 17 00:00:00 2001 From: Gannon McGibbon Date: Thu, 29 Nov 2018 14:43:38 -0500 Subject: Allow aliased attributes in update Allow aliased attributes to be used in `#update_columns` and `#update`. --- activerecord/lib/active_record/attribute_methods/dirty.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'activerecord/lib/active_record/attribute_methods') diff --git a/activerecord/lib/active_record/attribute_methods/dirty.rb b/activerecord/lib/active_record/attribute_methods/dirty.rb index ebc2252c50..45e4b8adfa 100644 --- a/activerecord/lib/active_record/attribute_methods/dirty.rb +++ b/activerecord/lib/active_record/attribute_methods/dirty.rb @@ -158,9 +158,13 @@ module ActiveRecord end private - def write_attribute_without_type_cast(attr_name, _) - result = super - clear_attribute_change(attr_name) + def write_attribute_without_type_cast(attr_name, value) + name = attr_name.to_s + if self.class.attribute_alias?(name) + name = self.class.attribute_alias(name) + end + result = super(name, value) + clear_attribute_change(name) result end -- cgit v1.2.3