Method: ActiveRecord::ConnectionAdapters::Transaction#commit_records

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

#commit_recordsObject



298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 298

def commit_records
  if records
    begin
      ite = unique_records

      if @run_commit_callbacks
        instances_to_run_callbacks_on = prepare_instances_to_run_callbacks_on(ite)

        run_action_on_records(ite, instances_to_run_callbacks_on) do |record, should_run_callbacks|
          record.committed!(should_run_callbacks: should_run_callbacks)
        end
      else
        while record = ite.shift
          # if not running callbacks, only adds the record to the parent transaction
          connection.add_transaction_record(record)
        end
      end
    ensure
      ite&.each { |i| i.committed!(should_run_callbacks: false) }
    end
  end

  if @run_commit_callbacks
    @callbacks&.each(&:after_commit)
  elsif @callbacks
    connection.current_transaction.append_callbacks(@callbacks)
  end
end