Understanding rails transactions

Hi,

I’m a bit confused about Rails transactions. Are these Rails
transactions:

Model.transaction do

end

or does the above code actually start a database transaction? If this
starts a db transaction, what sort of db transaction does this start? I
would not want serializable transactions as this would be expensive. If
this starts a Rails application level txn, is there a way to start a db
level txn and why would anybody use an application level txn if
something like this exists in Rails.

Thanks,

Sam

On Friday 29 September 2006 05:36, Sam D. wrote:

Hi,

I’m a bit confused about Rails transactions. Are these Rails
transactions:

Model.transaction do

end

or does the above code actually start a database transaction?

The outermost of these blocks starts a database transaction. Leaving the
block normally will commit the transaction, leaving it with an
exception will rollback the transaction.

When transaction blocks are nested, in the same method or inside called
methods, the inner transaction blocks neither start nor end
transactions.

If
this starts a db transaction, what sort of db transaction does this
start? I would not want serializable transactions as this would be
expensive.

Rails just sends BEGIN/COMMIT/ROLLBACK to the database without an
isolation level. If you want any specific one, you have to set it by
other means.

Michael


Michael S.
mailto:[email protected]
http://www.schuerig.de/michael/