views:

110

answers:

2

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?

A: 

transaction is a class method on ActiveRecord::Base so you can do it like this:

Model.transaction do
  ...
end

or if you prefer to do it without a specific model:

ActiveRecord::Base.transaction do
  ...
end

It may also depend on which database you are using, I know for sure that works on mysql but not sure about others.

mcostanza
You misread the question. I want to disable transactions, not use them. Your examples explicitly use transactions.ActiveRecord uses transactions at various points, and those are the ones I want to remove.
Daniel Huckstep
Marked this one down for being irrelevant.
Greg Malcolm
A: 

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
Daniel Huckstep