aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods
diff options
context:
space:
mode:
authorYuya Tanaka <yuya.presto@gmail.com>2018-08-22 20:00:19 +0900
committerYuya Tanaka <yuya.presto@gmail.com>2018-08-28 16:32:23 +0900
commit34f075fe5666dcf924606f8af2537b83b7b5139f (patch)
tree30c11dda125da7385954802dfa2093a0ff7e04fd /activerecord/lib/active_record/attribute_methods
parent1353610ff2ab4d16d022d5c31d5b4e5d908e05a8 (diff)
downloadrails-34f075fe5666dcf924606f8af2537b83b7b5139f.tar.gz
rails-34f075fe5666dcf924606f8af2537b83b7b5139f.tar.bz2
rails-34f075fe5666dcf924606f8af2537b83b7b5139f.zip
Mutation tracker should be cleared before continuing around callbacks
`changes_applied` should be called before continuing around callback chain. Otherwise the mutation tracker returns old value for methods like `changed`? or `id_in_database` in around callbacks. Also methods depend on `id_in_database`, like `update_column`, are not working in `around_create` callbacks. ``` class Foo < ActiveRecord::Base around_create :around_create_callback def around_create_callback ... yield p id_in_database # => nil update_column(:generated_column, generate_value) # silently fails end ... end ```
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods')
-rw-r--r--activerecord/lib/active_record/attribute_methods/dirty.rb11
1 files changed, 6 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/dirty.rb b/activerecord/lib/active_record/attribute_methods/dirty.rb
index 233ee29fac..bc25837fab 100644
--- a/activerecord/lib/active_record/attribute_methods/dirty.rb
+++ b/activerecord/lib/active_record/attribute_methods/dirty.rb
@@ -16,9 +16,6 @@ module ActiveRecord
class_attribute :partial_writes, instance_writer: false, default: true
- after_create { changes_applied }
- after_update { changes_applied }
-
# Attribute methods for "changed in last call to save?"
attribute_method_affix(prefix: "saved_change_to_", suffix: "?")
attribute_method_prefix("saved_change_to_")
@@ -168,11 +165,15 @@ module ActiveRecord
end
def _update_record(*)
- partial_writes? ? super(keys_for_partial_write) : super
+ affected_rows = partial_writes? ? super(keys_for_partial_write) : super
+ changes_applied
+ affected_rows
end
def _create_record(*)
- partial_writes? ? super(keys_for_partial_write) : super
+ id = partial_writes? ? super(keys_for_partial_write) : super
+ changes_applied
+ id
end
def keys_for_partial_write