You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 31, 2018. It is now read-only.
class MyModel ...
after_save do
run_after_commit { puts "run after commit called" }
end
end
MyModel.transaction do
model1 = MyModel.find(1)
model1.title = "1"
model1.save!
model2 = MyModel.find(1) # same "record"
model2.title = "2"
model2.save!
end
Output is only a single:
run after commit called
If we'd instead save the queue within the transaction object.
after_commit_queue doesn't seem to work for nested transactions, as it stores its queue within the model object and ActiveRecord only runs the after_commit hook once for each uniq record. See https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb#L80-L89
Thus, if an individual record is updated twice within a single transaction, the run_after_commit runs only once. Compare this overly simplified example:
Output is only a single:
If we'd instead save the queue within the transaction object.
It would work as IMO expected. What do you think?