method
prepare_instances_to_run_callbacks_on
rails latest stable - Class:
ActiveRecord::ConnectionAdapters::Transaction
prepare_instances_to_run_callbacks_on(records)private
No documentation available.
# File activerecord/lib/active_record/connection_adapters/abstract/transaction.rb, line 267
def prepare_instances_to_run_callbacks_on(records)
records.each_with_object({}) do |record, candidates|
next unless record.trigger_transactional_callbacks?
earlier_saved_candidate = candidates[record]
next if earlier_saved_candidate && record.class.run_commit_callbacks_on_first_saved_instances_in_transaction
# If the candidate instance destroyed itself in the database, then
# instances which were added to the transaction afterwards, and which
# think they updated themselves, are wrong. They should not replace
# our candidate as an instance to run callbacks on
next if earlier_saved_candidate&.destroyed? && !record.destroyed?
# If the candidate instance was created inside of this transaction,
# then instances which were subsequently loaded from the database
# and updated need that state transferred to them so that
# the after_create_commit callbacks are run
record._new_record_before_last_commit = true if earlier_saved_candidate&._new_record_before_last_commit
# The last instance to save itself is likeliest to have internal
# state that matches what's committed to the database
candidates[record] = record
end
end