On Tue, Nov 17, 2009 at 8:19 AM, Jeremy Evans <[email protected]> wrote:
> On Nov 16, 7:51 pm, John Firebaugh <[email protected]> wrote:
>> Shouldn't the transaction around Model#_save be rolled back if one of
>> the before hooks returns false?
>>
>> It will be if raise_on_save_failure is set to true because that raises
>> an exception, but if raise_on_save_failure is false, the transaction
>> is committed even though the save fails.
>
> What's the use case for this?  The before hooks are the first things
> run, so the only thing I can think of is you want to rollback changes
> made by a previous before hook.  Is that why you want this?

Yes, I have a model that has some nested_attributes-like functionality
triggered in before_save instance hooks. If any of the before hooks
fail, I want all of them rolled back.

> You could probably implement this by raising Rollback in save_failure
> if raise_on_save_failure is false, and modifying Model#save to rescue
> Rollback if transactions aren't being used.  I'm not sure I like that
> approach, though, unless you are checking whether or not transactions
> are being used, as otherwise you could be swallowing exceptions that
> you didn't generate (such as the user raising Rollback in a before
> hook).

How about the attached patch?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Attachment: 0001-Ensure-transactions-around-save-and-destroy-are-roll.patch
Description: Binary data

Reply via email to