On Jun 26, 2006, at 6:41 PM, [email protected] wrote:
ending a single database transactions which spans two different
kinds of models/tables ?
When you start a database transaction it’s in effect for that
connection as a whole, not any particular table or row. The
Account.transaction and dennis.transaction class and instance methods
are simply conveniences which delegate to the current database
A.transaction do # begin
B.create! # insert into bs (attrs) values (?)
C.create! # insert into cs (attrs) values (?)
end # commit
If you have models whose tables are in different databases and you
need transactional guarantees, you’re out of luck - distributed
transactions are unsupported.
In your example you use an object transaction as well. You rarely
want this: if a database transaction rolls back, you’ll want to, say,
display dennis.errors. But the object transaction rolls dennis back
to his state - including dennis.errors - before the withdrawal.