I have two tables in my database, Property and Address. I''m trying to create a view that will allow the user to enter data for the Property table and the Address table. I created a static scaffold based on the Property model and was able to tweak the form to add the address fields. I then modified the controller to insert the Address record in the database. This is working, and I end up with a new record in both tables. Here''s my dilema. . .I need to be able to insert the id of the Address record into the addresses_id column of the Property record (addresses_id is the foreign key column in the Property table). How do I retrieve the id of the new Address record from the database (which is MySQL by the way) so I can add it to the Property before saving it to the database? Is there a better approach for dealing with related tables/models? Thanks. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
iiminar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Sep-02 17:23 UTC
Re: Updating Multiple Tables From Single View
Maybe there is more sofisticated approach in doing this, but the first thing that came to my mind is: property.save property.reload address.property_id = property.id address.save --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---