> -----Original Message-----
> From: Carl Youngblood [mailto:carl / youngbloods.org] 

> Austin Ziegler wrote:
>>> Be aware, though, that the objects will not have their instance
>>> data returned to their state before the transaction started.
>>> You'll have to deal with that yourself (just as in the case of
>>> Validations). Also have in mind that exceptions thrown within a
>>> transaction block will be propagated (after triggering the
>>> ROLLBACK), so you should be ready to catch those in your
>>> application code.
>> One might want to consider using Transaction::Simple if you need
>> application-level rollback, not just database-level rollback. I
>> have not yet had time to implement a block form, but it is
>> planned.
> Why not even add Transaction::Simple to Active Record?
 
I am not opposed to DHH including Transaction::Simple with
ActiveRecord, but there are limitations to Transaction::Simple that
should be made clear. Essentially, Transaction::Simple operates only
on those variables about which it knows. The standard case is:

  foo.extend(Transaction::Simple)
  foo.start_transaction
  # do stuff with foo
  if error
    foo.abort_transaction
  else
    foo.commit_transaction
  end

The block form will come in two ways:

    # (1)
  foo.extend(Transaction::Simple)
  foo.start_transaction do
    # do stuff with foo
    foo.abort_transaction if error
  end # implied #commit_transaction
  # #abort_transaction will be called if an exception is caught

    # (2)
  Transaction::Simple.start(foo) do |foo_t|
    # do stuff with foo_t
    foo_t.abort_transaction if error
  end # implied #commit_transaction
  # WARNING! foo will now be extended with Transaction::Simple for
  # the rest of its natural life. Or is there a way to unextend a
  # module from an object?

The two transactions are -- currently -- perhaps incompatible, and
it does involve a bit of overhead.

-austin
--
austin ziegler * austin.ziegler / evault.com