# Transactions (commit and rollback)

**URL:** <https://discuss.rubyonrails.org/t/transactions-commit-and-rollback/28604>\
**Category:** rubyonrails-talk\
**Created:** [April 26, 2008, 11:28am UTC](https://discuss.rubyonrails.org/t/transactions-commit-and-rollback/28604 "2008-04-26T11:28:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miquel\_Oliete](https://avatars.discourse-cdn.com/v4/letter/m/d26b3c/32.png) [@Miquel\_Oliete](https://discuss.rubyonrails.org/u/Miquel_Oliete)\
**Post date:** [April 26, 2008, 11:28am UTC](https://discuss.rubyonrails.org/t/transactions-commit-and-rollback/28604/1 "2008-04-26T11:28:05Z")

</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
