I’m using the Zend Framework database relationships for a couple of weeks now. My first impression is pretty good, but I do have a question related to inserting related data into multiple tables. For a little test application I’ve related two tables with each other by using a fuse table.
+---------------+ +---------------+ +---------------+
| Pages | | Fuse | | Prints |
+---------------+ +---------------+ +---------------+
| pageid | | fuseid | | printid |
| page_active | | fuse_page | | print_title |
| page_author | | fuse_print | | print_content |
| page_created | | fuse_locale | | ... |
| ... | | ... | +---------------+
+---------------+ +---------------+
Above is an example of my DB architecture
Now, my problem is how to insert related data to two separate tables and insert the two newly created ID’s into the fuse table at the same time. If someone could could maybe explain or give me a topic related tutorial. I would appreciate it!
I assume you got separate models for each table. Then simply insert stuff in
Printstable, store returned ID in variable. Then insert stuff inPagestable and store returned ID in another varialble. Eventually insert data in yourFusetable. You do not need any “at the same time” (atomic) operation here. ID of newly inserted rows are returned bysave()(I assume you use autoincrement fields for this).thus is pseudo code, so you may want to move inserts into your models and do somoe i.e. normalisation etc.
I also suggest paying more attention to fields naming convention. It usually helps and now you got
fuseidbut alsofuse_page. So it either should befuse_idorfusepage(not to mention I suspect this field stores id so it would befuse_page_idorfusepageid).