From: Kirk Haines Date: 2004-06-10T05:29:27+09:00 Subject: Re: [ANN] Active Record 0.8.3: Modules, mapping, and transactions On Thu, 10 Jun 2004 04:52:00 +0900, David Heinemeier Hansson wrote > It could very well be that you're interested in the data that cause > the invalidation. So let's imagine that name = "David" will cause > the transaction to fail. I'd really to be able to access that value > afterwards. This is how the validations stuff in AR works as well. > So attempt to validate the data, if it fails, you can present the > wrong data for correction. If a transaction fails because of an exception, the exception can be caught before the rollback, though. And if the rollback is an explicit one -- the code decides that something is wrong and calls a rollback before any exception is encountered -- then one can choose to do something with the incorrect value before the rollback. > That and, personally, I don't really need the object transactions > most of the time. So it's nice to be able to turn it off by not > specifically requiring it. Transactions are not free of performance > penalties (as Austin mentioned). I'm finding that object transactions are handy for performance and/or for validation. If one is making a lot of changes to an ORM object, but it's only the final value that is really of long term interest, wrapping everything in a transaction means that only the final value makes its way to the db. Or, if the values in the object are subject to user input and manipulation, you probably don't want to write that data out to the database until it has been validated. So while I wasn't sure when I implemented them, I'm finding myself using them all over the place. Performance...Hmmm. There is an overhead to transactions. That's one of the things I have been working on minimizing, myself. Can't really counter- argue you there. :) Here's another question -- is there any way to do transactions over object/row insertions with ActiveRecord? i.e. start a transaction; do something that creates a new object/row; incur and exception or decide that there is a problem and rollback; table/objects are unchanged. No? Maybe? Yes? My gut sense is that you can't because you do have to specify the objects to have transactions applied to them when entering the transaction block, and if the object doesn't exist then, you can't do that. However, am I wrong? Thanks again. This is interesting stuff. Kirk Haines