Welcome Guest, Not a member yet? Register   Sign In
Insert into multiple tables.
#4

[eluser]srpurdy[/eluser]
[quote author="Ralanyo" date="1344549571"]Thanks for the reply. I've been doing some research and there are a bunch of different opinions. Transactions is one that i found. I guess an orm makes it easier to work with table relationships.

My database is myisam right now and that doesn't support foreign keys. I know it's not that difficult to change the database to innodb, but I was wondering if others are developing without foreign key relationships somehow. easy to display with a join, but not so easy with inserts , updates and deletes.

I have one form that needs to insert data into a company table and a sales rep table. Eventually i want to be able to query data later to see all companies associates to a specific sales rep. (pretty sure I can do this with a join and where)

I also wanted to use active record. Some have said to write two separate insert statement in the model for each table. Is this standard practice?[/quote]

Yeah 2 inserts. I use it all the time frankly, and I've never had a row gone missing. Even in cases of 10,000 plus users actively using the systems in question. (not all at once obviously)

You can use $this->db->insert_id() if you need to extract the id of the first insert.

I've done as much as 5 or more at once depending on how complex the read queries would be. Never had an issue doing it this way so I don't see why not too.


Messages In This Thread
Insert into multiple tables. - by El Forum - 08-08-2012, 10:16 PM
Insert into multiple tables. - by El Forum - 08-08-2012, 10:54 PM
Insert into multiple tables. - by El Forum - 08-09-2012, 02:59 PM
Insert into multiple tables. - by El Forum - 08-09-2012, 08:51 PM
Insert into multiple tables. - by El Forum - 08-09-2012, 09:01 PM
Insert into multiple tables. - by El Forum - 08-09-2012, 09:07 PM
Insert into multiple tables. - by El Forum - 08-09-2012, 09:09 PM
Insert into multiple tables. - by El Forum - 08-09-2012, 09:15 PM



Theme © iAndrew 2016 - Forum software by © MyBB