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