Rails transactions issue with rollback

Hi,

I have a transaction in which a duplicate key exception is being thrown
by MySQL. I assume this happens when I try to do a save. The problem
is that before the save, I do a destroy on another object as part of the
transaction. Catching the exception by doing this,

User.transaction do
begin
objA.destroy
objB.save <-- causing exception
rescue Exception => exc
flash[:notice] = …
end
end

does not rollback the destroy. Any help would be appreciated.

Thanks,

Sam

Could this be because of using MyISAM tables rather than InnoDB?

Thanks.

On 10/2/06, Sam D. [email protected] wrote:

I have a transaction in which a duplicate key exception is being thrown
by MySQL. I assume this happens when I try to do a save. The problem
is that before the save, I do a destroy on another object as part of the
transaction. Catching the exception by doing this,

Rescue the exception outside of the transaction block. Be sure to use
a
database that supports transactions (not MySQL + MyISAM.)

begin
User.transaction do
objA.destroy
objB.save!
end
rescue Exception => exc
flash[:notice] = …
end

jeremy

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs