# Transactions are just not working

**URL:** <https://www.ruby-forum.com/t/transactions-are-just-not-working/71805>\
**Category:** Rails\
**Created:** [October 11, 2006, 4:51pm UTC](https://www.ruby-forum.com/t/transactions-are-just-not-working/71805 "2006-10-11T16:51:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RoR\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/77aa72/32.png) [@RoR\_newbie](https://www.ruby-forum.com/u/RoR_newbie)\
**Post date:** [October 11, 2006, 4:51pm UTC](https://www.ruby-forum.com/t/transactions-are-just-not-working/71805/1 "2006-10-11T16:51:07Z")

</div>

Here’s my method that has the transaction in it:  
[http://rafb.net/paste/results/yIuwpz49.html](http://rafb.net/paste/results/yIuwpz49.html)

The message, forumobject and groupright are all models within the same  
database.

I have some validations for each and my problem is that when the  
validation for message fails, other objects still get saved.

Why is this happening?

---

<div class="post-metadata">

**Author:** ![RoR\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/77aa72/32.png) [@RoR\_newbie](https://www.ruby-forum.com/u/RoR_newbie)\
**Post date:** [October 11, 2006, 6:04pm UTC](https://www.ruby-forum.com/t/transactions-are-just-not-working/71805/2 "2006-10-11T18:04:33Z")

</div>

On Wed, Oct 11, 2006 at 04:51:07PM +0200, RoR newbie wrote:  
}  
} Here’s my method that has the transaction in it:  
} [http://rafb.net/paste/results/yIuwpz49.html](http://rafb.net/paste/results/yIuwpz49.html)  
}  
} The message, forumobject and groupright are all models within the same  
} database.  
}  
} I have some validations for each and my problem is that when the  
} validation for message fails, other objects still get saved.  
}  
} Why is this happening?

Without actually seeing your code, my guess is that you are using MySQL  
with MyISAM tables, which do not support transactions. Insert rant here  
about how MySQL is a lousy RDBMS.

–Greg

---

<div class="post-metadata">

**Author:** ![RoR\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/77aa72/32.png) [@RoR\_newbie](https://www.ruby-forum.com/u/RoR_newbie)\
**Post date:** [October 11, 2006, 7:03pm UTC](https://www.ruby-forum.com/t/transactions-are-just-not-working/71805/3 "2006-10-11T19:03:17Z")

</div>

You need to use the .save! method which throws an exception,  
or generate your own exception if there’s an error. Transactions  
only roll back on an exception.

On Oct 11, 2006, at 7:51 AM, RoR newbie wrote:

> Why is this happening?
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
– Tom M.

---

<div class="post-metadata">

**Author:** ![RoR\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/77aa72/32.png) [@RoR\_newbie](https://www.ruby-forum.com/u/RoR_newbie)\
**Post date:** [October 11, 2006, 11:06pm UTC](https://www.ruby-forum.com/t/transactions-are-just-not-working/71805/4 "2006-10-11T23:06:48Z")

</div>

Tom M. wrote:

> You need to use the .save! method which throws an exception,  
> or generate your own exception if there’s an error. Transactions  
> only roll back on an exception.

Can this be done so that it won’t give me the exception screen but justs  
rolls back and goes on?

---

<div class="post-metadata">

**Author:** ![RoR\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/77aa72/32.png) [@RoR\_newbie](https://www.ruby-forum.com/u/RoR_newbie)\
**Post date:** [October 11, 2006, 11:41pm UTC](https://www.ruby-forum.com/t/transactions-are-just-not-working/71805/5 "2006-10-11T23:41:43Z")

</div>

RoR newbie wrote:

> Tom M. wrote:
> 
> > You need to use the .save! method which throws an exception,  
> > or generate your own exception if there’s an error. Transactions  
> > only roll back on an exception.
> 
> Can this be done so that it won’t give me the exception screen but justs  
> rolls back and goes on?

If you catch the exception in a rescue block and do nothing, yes.

---

<div class="post-metadata">

**Author:** ![RoR\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/77aa72/32.png) [@RoR\_newbie](https://www.ruby-forum.com/u/RoR_newbie)\
**Post date:** [October 12, 2006, 2:13am UTC](https://www.ruby-forum.com/t/transactions-are-just-not-working/71805/6 "2006-10-12T02:13:17Z")

</div>

On Oct 11, 2006, at 2:06 PM, RoR newbie wrote:

> Tom M. wrote:
> 
> > You need to use the .save! method which throws an exception,  
> > or generate your own exception if there’s an error. Transactions  
> > only roll back on an exception.
> 
> Can this be done so that it won’t give me the exception screen but  
> justs  
> rolls back and goes on?

Yes.

That is a given when wrapped in a transaction.

–  
– Tom M.
