Forum: Ruby on Rails Transaction save?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ruby R. (Guest)
on 2006-06-12 19:27
I have these two records which are saved in two different tables. The
problem is unless the first record (Cr) is saved the second (Crmapping)
doesn't get created because of referencing. It's my assumption that
create() does not need explicit save() method. It instantiates the model
obj and saves it into db. But then any ideas on why the Cr.create is not
creating a record?

if (a == b) then
           :id => vcr,
           :status => 'NEW',
           :er => 'N',
           :issuedate =>,
           :needbydate =>

           :k_id => found[0].id,
           :c_id => vcr,
           :sys_creation_date =>

Since the first record was not created when executing the second I get
Mysql::Error: #23000Cannot add or update a child row: a foreign key
constraint fails...

Clayton C. (Guest)
on 2006-06-13 00:32
(Received via mailing list)
You can wrap blocks in a transaction

<Model>.transaction do
This topic is locked and can not be replied to.