Inserting ID field value from master table into child table

micben

New member
Hello Eugenio,

When using your master/details feature, how do I copy automatically the ID field from the master into the linked field from the child table?

It looks like a "SQL:" default value is not the solution because it takes only the 1st record of the main table and not the corresponding one.

As well, I don't know how to activate the timestamp function on this child table (insertion date and update). It provides me 00:00:00 or nothing at all.

Thanks !
Benoît



You are using DaDaBIK version 7.3.3 enterprise, installed on 01-11-2017, the last version of DaDaBIK is 7.3.3 released on 07-26-2016

You are runnning the last release of DaDaBIK

PHP Version: 5.6.30

mysql version: 5.6.28-76.1-log

Web server: Apache

Client: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
 

micben

New member
By the way, this is about inserting new records in the child table, linked to a specific record from the master table...
 

eugenio

Administrator
Staff member
Hello,
you don't have to do anything: if the "foreign key" field in the child table is a select_single linking the id of the master table, the field is automatically filled by DaDaBIK.

About the second question: with timestamp do you mean an insert_date field? If yes, It doesn't metter if an insert_date field is in a child table or in a master table, it always works in the same way, are you sure it is not working only in that table?

Best,
 

micben

New member
Thanks !

1) Default value of the linked field: Even when there is nothing in the default value parameter, it doesn't fill the linked field in the child table.

2) About the timestamp, I got 00/00/00 00:00:00 in the parent table but nothing at all in the timestamp field of the child table... The timestamp worked correctly in PHPMyAdmin and when I first imported this field in Dadabik but I just changed the field type in the Dadabik parameters and it doesn't show up anymore. Not even the zeros of the parent table.

Benoît
 

eugenio

Administrator
Staff member
1) Open the demo n.1 in the DaDaBIK Web site, go to the invoices table, enter in edit mode the first invoice and add a new item (master/details). As you can see the ID of the related invoice is automatically filled. Is this what you want to get? If yes, click on "edit this app" in the demo and see how the field id_invoice in the table id_invoice_items has been set, are you sure that in your case you have exactly the same settings?

2) I still don't understand if you mean an insert_date field type or a timestamp content type. If you need to collect automatically the date of insertion you just need to select insert_date in DaDaBIK, the corresponding MySQL field type must be date or datetime (NOT timestamp).

Best,
 

micben

New member
Hi Eugenio,

Thanks for trying to find out what's going on.

1) My master/details doesn't look exactly like yours. There is a separator at the end of the record from the main table and the remaining part of the page is a list of the corresponding records from the child table. When a try to insert a new record in this child (clicking on the "Create new item" button), the linked field is not copied into this 2nd table. Then, I need to insert the right ID manually.

2) I have set again the insert_date in DaDaBIK and I changed timestamp for datetime in MyPHPAdmin but the insert and update fields don't display anything, even in the details view, in the parent table and in the child table as well.

If only you can have a real look on my settings. It's hard to describe, sometimes. :)

Thanks !
Benoît
 

eugenio

Administrator
Staff member
Hello,

1) I meant the form configurator settings for the field id_invoice in the table id_invoice_items must be exactly the same you have, are they? If not, adjust them

2) Try a simple test: create a new table having just two fields, name_test (varchar) and date_test (date). Install the table in dadabik, set the date_test field as insert_date, hide the date_test field from the insert form, insert a new record specifying name_test (only field in the form). The field date_test of the record just inserted must contain the current date, it must work.

best,
 

micben

New member
Thanks !

Do I always have to hide the fields that need to be filled automatically? It may resolve the two problems (linked field and date)...

Benoît
 

eugenio

Administrator
Staff member
Usually yes, but in the online help, for each field type, there are instructions. Eg. for insert_date:

insert_date: the current date will be automatically inserted into this field when you insert a new record in your table; an insert_date field must be excluded from the insert form, see below (Field present in the insert form?). Note that the corresponding database field type must be date
 
Hi Eugenio,
I can't find the described table "invoices" in your online demo anymore to determine the settings there. Could you give me another example for the described situation (automatic population of field in child table with id of entry in master table when inserting new record in child table)?

Thanks
Andreas

You are using DaDaBIK version 8.2-Lerici enterprise, installed on 01-14-2018 (installation code: 132625a5b34516cf0a), the latest version of DaDaBIK is 8.2-Lerici released on 12-19-2017
You are runnning the last release of DaDaBIK
PHP Version: 5.6.32
mysql version: 5.7.20
Web server: Apache/2.4.29 (Unix) PHP/5.6.32
Client: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:58.0) Gecko/20100101 Firefox/58.0
 

larryk

Well-known member
Is the Demo 2 still showing the process?

The:
(automatic population of field in child table with id of entry in master table when inserting new record in child table)?

Said another way, the foreign key needs to be populated in the child table, taken from the master table.
I must be doing something wrong, as my foreign key is always 0.

thanks
 
Top