Save 1 to 1 DB Relation

save data to two related database tables in a form.

Overview

The issue is needing to insert data into a primary table and then into a related details table with the correct foreign key.
Use two Save Data actions in the form. After the first action saves to the main table, use the generated ID variable in the Insert Data Override of the second action to set the foreign key for the details table.

Answered
ChronoForms v6
ig igmz 12 Apr, 2018
Hello.

I have to tables in mi database:

MAIN with an ID
MAIN_DETAILS with a forgeing key to MAIN

I have a form to get both table data so I that I want to do is save first details to MAIN table and after save data to MAIN_DETAILS with the fk included.

Please, anyone could help me??

Thanks in advance!
Max_admin Max_admin 19 Apr, 2018
Answer
Hello igmz,

Just use 2 "Save data" actions, after the first one the id value should be available under:
{var:save_data_name.id}
You can use that in the "Insert data override" of the 2nd "Save data".

You can check the whole list of available variables by using a Debugger

Best regards
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.