You can wrap blocks in a transaction
<Model>.transaction do
...
end
-----Original Message-----
From: rails-bounces@lists.rubyonrails.org
[mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Ruby Rails
Sent: Monday, June 12, 2006 8:28 AM
To: rails@lists.rubyonrails.org
Subject: [Rails] Transaction save?
Hi,
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
Cr.create(
:id => vcr,
:status => ''NEW'',
:er => ''N'',
:issuedate => Date.today,
:needbydate => Date.today
)
Crmapping.create(
:k_id => found[0].id,
:c_id => vcr,
:sys_creation_date => Date.today
)
end
Since the first record was not created when executing the second I get
error:
Mysql::Error: #23000Cannot add or update a child row: a foreign key
constraint fails...
Thanks
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
Rails mailing list
Rails@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails