Method: ActiveRecord::ConnectionAdapters::Transaction#before_commit_records

Defined in:
activerecord/lib/active_record/connection_adapters/abstract/transaction.rb

#before_commit_recordsObject



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 274

def before_commit_records
  if @run_commit_callbacks
    if records
      if ActiveRecord.before_committed_on_all_records
        ite = unique_records

        instances_to_run_callbacks_on = records.each_with_object({}) do |record, candidates|
          candidates[record] = record
        end

        run_action_on_records(ite, instances_to_run_callbacks_on) do |record, should_run_callbacks|
          record.before_committed! if should_run_callbacks
        end
      else
        records.uniq.each(&:before_committed!)
      end
    end

    @callbacks&.each(&:before_commit)
  end
  # Note: When @run_commit_callbacks is false #commit_records takes care of appending
  # remaining callbacks to the parent transaction
end