Scott,
Assuming Person model is dependent on Project model, in my controller action
I do this
begin
if project.save
if person.save
#do something
end
else
end
rescue StandardError
end
OR
In Project model you can do something like this ...... in my code below
image is a dependent child of incident substitute person and project
according to your needs.
after_create{|incident|
incident.image.incident_id = incident.incidentid
incident.image.app_login_modification = incident.image.app_login_creation
incident.app_login_creation
incident.image.creation_dt = incident.image.modification_dt incident.creation_dt
incident.image.save
}
hope this helps
-fanoflinux
On 8/1/06, Scott Walter <tx_scottwalter@yahoo.com>
wrote:>
> Hi,
>
> I have 2 models, how can I save both of them in one transaction?
>
> I want to do something like this:
>
> begin transaction
> project.save
> person.save
> end transaction
>
> The only examples I''ve seen is with saving 2 instances of the same
model
> in a transaction.
>
> thanks
>
> scott.
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060801/64d53493/attachment-0001.html