Thanks Jeremy. That helps. :)

On Monday, March 31, 2014 9:34:24 PM UTC-7, Jeremy Evans wrote:
>
>
> On Monday, March 31, 2014 7:39:01 PM UTC-7, Deepak Agrawal wrote:
>>
>> These are the models :
>>
>> class User < Sequel::Model
>>   self.raise_on_save_failure = false
>> end
>>
>> class Addresses < Sequel::Model
>>   many_to_one: user
>>   self.raise_on_save_failure = false
>> end
>>
>>
>> address = Addresses.find(id: 1)
>>
>> user = address.user
>>
>> DB.transaction do
>>    address.delete
>>    user.save
>> end
>>
>> In the above code if user.save returns nil as some validation fails the 
>> transaction is not rollback
>> and that address is still deleted.
>>
>> Is it possible if user.save fails, address.delete is rollbacked where 
>> raise_on_save_failure = false.
>>
>> The transaction does rollback if raise_on_save_failure = true but dont 
>> want to set it true.
>>
>
> This is expected behavior.  If you want to explicitly rollback in save 
> fails even if raise_on_save failure is false, you have two options.  One is 
> enabling exceptions for that particular save:
>
>  DB.transaction do
>    address.delete
>    user.save(:raise_on_failure=>true)
> end
>
> The second is explicitly rolling back if you detect a save failure:
>
>  DB.transaction do
>    address.delete
>    raise Sequel::Rollback unless user.save
> end
>
> Thanks,
> Jeremy
>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to