I have model Program and model PointOfContact. Program belongs to
PointOfContact. There is a form to update values, which shows attributes
from both models on one form. What is the best way to update the models
with one call. I tried this and it did not work
@program_old = Program.find(params[:id]) @program = Program.new(params[:program]) @program.id = @program_old.id @point_of_contact = PointOfContact.new(params[:point_of_contact]) @point_of_contact_old =
@point_of_contact.id = @point_of_contact_old.id
current_user = session[:user].login @program.updated_by = current_user @point_of_contact.updated_by = current_user @program.pointOfContact = @point_of_contact @program.save!
This does not work and gives the error:
Violation of PRIMARY KEY constraint ‘PK__point_of_contact__1F2E9E6D’.
Cannot insert duplicate key in object ‘point_of_contacts’ …
Doing update_attributes on individual model works but that is two calls?
Is there a better way to do it?