aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-05-27 12:06:58 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-05-27 12:06:58 +0900
commit17bf62033edd4f0934c9f4a9e0c7a5f0f765975b (patch)
tree55ee2fa5fe2730283e6f520e2bb395ad339802db /activerecord/lib/active_record
parentced783fe74ea8683fbc09812ed0e0cadf449a358 (diff)
downloadrails-17bf62033edd4f0934c9f4a9e0c7a5f0f765975b.tar.gz
rails-17bf62033edd4f0934c9f4a9e0c7a5f0f765975b.tar.bz2
rails-17bf62033edd4f0934c9f4a9e0c7a5f0f765975b.zip
Fix that association's after_touch is not called with counter cache
Since #31405, using `#increment!` with touch option instead of `#touch` to touch belongs_to association if counter cache is enabled. It caused the regression since `#increment!` won't invoke after_touch callbacks even if touch option is given. To fix the regression, make `#increment!` invokes after_touch callbacks if touch option is given. Fixes #31559. Fixes #32408.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/callbacks.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/callbacks.rb b/activerecord/lib/active_record/callbacks.rb
index fd6819d08f..0a29c5134e 100644
--- a/activerecord/lib/active_record/callbacks.rb
+++ b/activerecord/lib/active_record/callbacks.rb
@@ -318,6 +318,10 @@ module ActiveRecord
_run_touch_callbacks { super }
end
+ def increment!(*, touch: nil) # :nodoc:
+ touch ? _run_touch_callbacks { super } : super
+ end
+
private
def create_or_update(*)