On 8 Aug 2006, at 16:14, Matt S. wrote:
From reading the Agile book, I gather that once I wrap the request
transaction I loose the validation state, so I have no easy what of
knowing what went wrong.
You only lose the validation if you also have the transaction roll
back the active record object as well as the database.
If you do this:
You probably want to do
The transaction aborts if an exception is thrown, not if the save
fails. So you need to use save! to get the RecordInvalid exception
user has not been rolled back, so contains all the errors from when
it was saved
flash[:notice] "Insert rolled back... but why..??"
Is this something people would recommend?
if user.errors.count == 0
if user_details.errors.count == 0
perform transaction_routine(user, user_details)
Use the transaction if you need thread-safety (you don’t need thread
safety if you are only serving with a single process, but that
doesn’t mean it’s not worth thinking about upfront). The transaction
in itself won’t magically make things threadsafe though; you need to
think carefully about your failure scenarios and whether all of them
cause an exception. For example, your case above creates a user
record, then a user_details record. Suppose a separate thread updates
the user record before the user_details record has been saved. Is
this a problem?
Ben B. - Director
Tel: 01223 708370 / 07786 916043