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.