how can get auto-increment?
how can get auto-increment?
moonoo1
Posts: 11Questions: 6Answers: 0
hi
I am an editor user.
I insert to table A and set the auto-increment value to
I need to insert it in table B.
In this case
What should I do?
This question has accepted answers - jump to:
Answers
That sounds like a parent child relationship. You make an insert into the parent table and get an auto-increment value: The primary key = the id field of the new record.
When you make an insert into the child table you would need to select the parent table record and insert the parent table's id into the child table as a foreign key.
For that purpose you can use a "select" field for example.
https://editor.datatables.net/reference/field/select
Here is an example:
https://editor.datatables.net/examples/simple/join.html
In the example "sites" is the parent table and "users" is the child table: One "site" can have many "users", but one "user" can only have one "site". That is a 1:N relationship.
If you have N:M relationships (site can have many users and user can have many sites) you would need a link table between "users" and "sites". It would consist of the ids of "user" and "sites" and you could call it "users_have_sites" or vice versa. For that use case here is an example as well:
https://editor.datatables.net/examples/advanced/joinLinkTable.html
Thank you for a detailed description.
My question is wrong.
I'm not talking about the output list ,it's a matter of saving a new. [action=create]
for example
In order and order details
how can get the pk of the order
How should I insert it to the order details table?
This example from this thread may help. It's demonstrating how to update the second table with the combined ages in the first. That would probably be a good template for what you're trying to achieve.
Colin
Another option is to use a server-side event to write to the second table when a certain action happens.
Allan