Daniel Huckstep Daniel Huckstep - 6 months ago 56
Ruby Question

Disable transactions in ActiveRecord

How do I disable transactions in Rails' ActiveRecord? I have a specific situation where I want them to go away I can't seem to find anything useful out there. Is it even possible?

Answer

Poor man's "no transactions"

# Force the loading of AR stuff
ActiveRecord::Base.connection.execute('SELECT 1')

# Remove transactions
ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
  def begin_db_transaction
  end

  def commit_db_transaction
  end
end
Comments