# Transactions (commit and rollback)

**URL:** <https://www.ruby-forum.com/t/transactions-commit-and-rollback/135929>\
**Category:** Rails\
**Created:** [April 26, 2008, 1:28pm UTC](https://www.ruby-forum.com/t/transactions-commit-and-rollback/135929 "2008-04-26T13:28:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miquel\_O](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac91a4/32.png) [@Miquel\_O](https://www.ruby-forum.com/u/Miquel_O)\
**Post date:** [April 26, 2008, 1:28pm UTC](https://www.ruby-forum.com/t/transactions-commit-and-rollback/135929/1 "2008-04-26T13:28:53Z")

</div>

Hi there

I’m coding an action where I have to create two related objects  
(models). The thing is that the second one uses the first one’s id  
value as its id (the first tables’s id is autoincrement and the second  
table’s id is not and get the value from the first table’s id.

How can I do to open a transaction in order to either create both  
objects if everything is ok or create no object is something is wrong  
(commit or rollback).

Thanks in advance

Regards

–

Miquel (a.k.a. Ktalà a.k.a. Ton)  
Linux User #286784  
GPG Key : 4D91EF7F  
Debian GNU/Linux (Linux wolverine 2.6.23.1)

Welcome to the jungle, we got fun and games  
Guns n’ Roses
