diff options
author | Michael Ryan <perceptec@gmail.com> | 2015-02-18 17:55:48 -0500 |
---|---|---|
committer | Michael Ryan <perceptec@gmail.com> | 2015-02-18 18:30:05 -0500 |
commit | b9a1e9a4b2289de199b214a542aa9fd3cb19be54 (patch) | |
tree | a9f68a591fd3d430e4a77295a85a1a54961ae481 /activerecord/CHANGELOG.md | |
parent | 83be86933d7faf43ff1717f4258d54fc72d3193c (diff) | |
download | rails-b9a1e9a4b2289de199b214a542aa9fd3cb19be54.tar.gz rails-b9a1e9a4b2289de199b214a542aa9fd3cb19be54.tar.bz2 rails-b9a1e9a4b2289de199b214a542aa9fd3cb19be54.zip |
Add `ActiveRecord::Base.suppress`
Diffstat (limited to 'activerecord/CHANGELOG.md')
-rw-r--r-- | activerecord/CHANGELOG.md | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index a3b680f09d..e52c142dc2 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,32 @@ +* Add ActiveRecord::Base.suppress to prevent the receiver from being saved + during the given block. + + For example, here's a pattern of creating notifications when new comments + are posted. (The notification may in turn trigger an email, a push + notification, or just appear in the UI somewhere): + + class Comment < ActiveRecord::Base + belongs_to :commentable, polymorphic: true + after_create -> { Notification.create! comment: self, + recipients: commentable.recipients } + end + + That's what you want the bulk of the time. New comment creates a new + Notification. But there may well be off cases, like copying a commentable + and its comments, where you don't want that. So you'd have a concern + something like this: + + module Copyable + def copy_to(destination) + Notification.suppress do + # Copy logic that creates new comments that we do not want triggering + # notifications. + end + end + end + + *Michael Ryan* + * `:time` option added for `#touch` Fixes #18905. |