How to set transaction isolation level using ActiveRecord connection? How to set transaction isolation level using ActiveRecord connection? ruby-on-rails ruby-on-rails

How to set transaction isolation level using ActiveRecord connection?


This functionality is supported by ActiveRecord itself:

MyRecord.transaction(isolation: :read_committed) do  # do your transaction workend

It supports the ANSI SQL isolation levels:

  • :read_uncommitted
  • :read_committed
  • :repeatable_read
  • :serializable

This method is available since Rails 4, it was unavailable when the OP asked the question. But for any decently modern Rails application this should be the way to go.