Transactions (commit and rollback)

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