aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/transactions.rb
diff options
context:
space:
mode:
authorJames Miller <bensie@gmail.com>2013-02-13 12:27:06 -0800
committerJames Miller <bensie@gmail.com>2013-02-13 12:27:06 -0800
commitcaabed6c76eea0db99949f34c234ef1b2657392a (patch)
tree2271c8fc2593bf4afd7158165ac7d5c9a9a66a0a /activerecord/lib/active_record/transactions.rb
parent5d58948fe72e3b0422790b8adc0fab7bbf9e6573 (diff)
downloadrails-caabed6c76eea0db99949f34c234ef1b2657392a.tar.gz
rails-caabed6c76eea0db99949f34c234ef1b2657392a.tar.bz2
rails-caabed6c76eea0db99949f34c234ef1b2657392a.zip
Don't call after_commit when creating through an association and save fails, fixes #5802
Diffstat (limited to 'activerecord/lib/active_record/transactions.rb')
-rw-r--r--activerecord/lib/active_record/transactions.rb5
1 files changed, 4 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb
index 4a608e4f7b..4b7a388dc7 100644
--- a/activerecord/lib/active_record/transactions.rb
+++ b/activerecord/lib/active_record/transactions.rb
@@ -286,8 +286,11 @@ module ActiveRecord
end
# Call the after_commit callbacks
+ #
+ # Ensure that it is not called if the object was never persisted (failed create),
+ # but call it after the commit of a destroyed object
def committed! #:nodoc:
- run_callbacks :commit
+ run_callbacks :commit if destroyed? || persisted?
ensure
clear_transaction_record_state
end