Buy Now
Sign in

Table view for a one-to-many relationship

Mmax2 , January 23 at 21:26
M
Mmax2
Good evening.
I set up a Read data Function to get a list of records from two tables with a one-to-many relationship.
The debugger output seems correct, but if I try to display the result in a Table view, only two blank rows are displayed.
This is the debugger output:

Array
(
[f_read-data_soggetto_diario] => Array
(
[log] => Array
(
[0] => SELECT `Soggetto`.`id_soggetto` AS `Soggetto.id_soggetto`, `Soggetto`.`created` AS `Soggetto.created`, `Soggetto`.`created_by` AS `Soggetto.created_by`, `Soggetto`.`modified` AS `Soggetto.modified`, `Soggetto`.`modified_by` AS `Soggetto.modified_by`, `Soggetto`.`nome_ragsoc` AS `Soggetto.nome_ragsoc`, `Soggetto`.`indirizzo` AS `Soggetto.indirizzo`, `Soggetto`.`citta` AS `Soggetto.citta`, `Soggetto`.`cap` AS `Soggetto.cap`, `Soggetto`.`telefono` AS `Soggetto.telefono`, `Soggetto`.`email` AS `Soggetto.email`, `Soggetto`.`note` AS `Soggetto.note` FROM `my_soggetti` AS `Soggetto` WHERE `Soggetto`.`id_soggetto` = '8';
[1] => SELECT `Diario`.`id_diario` AS `Diario.id_diario`, `Diario`.`id_soggetto` AS `Diario.id_soggetto`, `Diario`.`created` AS `Diario.created`, `Diario`.`created_by` AS `Diario.created_by`, `Diario`.`modified` AS `Diario.modified`, `Diario`.`modified_by` AS `Diario.modified_by`, `Diario`.`data` AS `Diario.data`, `Diario`.`attivita` AS `Diario.attivita` FROM `my_diario` AS `Diario` WHERE `Diario`.`id_soggetto` IN ('8') ORDER BY `Diario.id_diario` DESC;
)

[var] => Array
(
[Soggetto] => Array
(
[id_soggetto] => 8
[created] => 2018-01-21 22:29:10
[created_by] => 307
[modified] => 0000-00-00 00:00:00
[modified_by] => 0
[nome_ragsoc] => Altro nome
[indirizzo] =>
[citta] =>
[cap] =>
[telefono] =>
[email] =>
[note] =>
)

[Diario] => Array
(
[0] => Array
(
[id_diario] => 13
[id_soggetto] => 8
[created] => 2018-01-23 22:04:00
[created_by] => 306
[modified] => 0000-00-00 00:00:00
[modified_by] => 0
[data] => 2018-01-24
[attivita] => Attività numero 2
)

[1] => Array
(
[id_diario] => 12
[id_soggetto] => 8
[created] => 2018-01-23 21:12:00
[created_by] => 306
[modified] => 0000-00-00 00:00:00
[modified_by] => 0
[data] => 2018-01-23
[attivita] => Prima attività
)

)

)

)

[f_switch_check_soggetto_diario_exists] => Array
(
[finished] => 1
[var] =>
)

[f_php_date_format] => Array
(
[returned] =>
[var] =>
)

)


In the Table view, Columns list are:
Diario.data:Data
Diario.attivita:Attività
I don't understand why the table isn't populated with the records.
Where is my mistake?
Thank you
Massimo
M
Mmax2
I noticed that with a simple query without relationship, the data for the table looks like this:

Array
(
[f_read-data_soggetti] => Array
(
[log] => Array
(
[0] => SELECT `Soggetti`.`id_soggetto` AS `Soggetti.id_soggetto`, `Soggetti`.`created` AS `Soggetti.created`, `Soggetti`.`created_by` AS `Soggetti.created_by`, `Soggetti`.`modified` AS `Soggetti.modified`, `Soggetti`.`modified_by` AS `Soggetti.modified_by`, `Soggetti`.`nome_ragsoc` AS `Soggetti.nome_ragsoc`, `Soggetti`.`indirizzo` AS `Soggetti.indirizzo`, `Soggetti`.`citta` AS `Soggetti.citta`, `Soggetti`.`cap` AS `Soggetti.cap`, `Soggetti`.`telefono` AS `Soggetti.telefono`, `Soggetti`.`email` AS `Soggetti.email`, `Soggetti`.`note` AS `Soggetti.note` FROM `my_soggetti` AS `Soggetti` ORDER BY `Soggetti.nome_ragsoc` ASC, `Soggetti.id_soggetto` DESC;
)

[var] => Array
(
[0] => Array
(
[Soggetti] => Array
(
[id_soggetto] => 8
[created] => 2018-01-21 22:29:10
[created_by] => 307
[modified] => 0000-00-00 00:00:00
[modified_by] => 0
[nome_ragsoc] => Altro nome
[indirizzo] =>
[citta] =>
[cap] =>
[telefono] =>
[email] =>
[note] =>
)

)

[1] => Array
(
[Soggetti] => Array
(
[id_soggetto] => 6
[created] => 2018-01-21 14:02:17
[created_by] => 307
[modified] => 0000-00-00 00:00:00
[modified_by] => 0
[nome_ragsoc] => Alvar Aalto
[indirizzo] =>
[citta] =>
[cap] =>
[telefono] =>
[email] =>
[note] => Architetto
)

)

)

)

)


Maybe the table can't accept an array of records as data provider?
Because in my first post I see there is an array like this: ModelName[n].field, while in the second and working one the array is Array[0].ModelName.field, Array[1].ModelName.field and so on.
Is there a way to feed the table with the first kind of data? Something like ModelName[n].field?
Thank you
Massimo
admin

Hi Massimo,

In the first data read you have the select type set to return the first record of the primary table, if you want to display the records of the secondary table then you can use {var:f_read-data_soggetto_diario.Diario}, in any case you need to provide the path to the data in the "var".

Best regards

Max
If your main question got answered then please mark the answer using the button!​
​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
M
Mmax2

Thank you very much for your reply.

If I put {var:f_read-data_soggetto_diario.Diario} in the "Data provider" field of the table view, nothing is displayed (blank page). The same if I put {var:f_read-data_soggetto_diario.Soggetto}.

If I put {var:f_read-data_soggetto_diario}, then the table is displayed, with only one row, and the columns header are: Soggetto.id_soggetto, Soggetto.created, ..., Diario.0, Diario.1 and so on.

The values in the columns with Soggetto.field_name are correctly displayed, while in the columns named Diario.0, Diario.1, ... there is "Notice: array to string conversion in C:\xampp\htdocs ... chronofc\views\tabletable_output.php on line 103 Array".

Is there any example where a one-to-many relationship is used? I mean, where the "Multiple matching records, foreign key in this table" is used.

Thank you again.

Massimo​

admin
Hi Massimo,
Apologies for the late reply!
It all depends on your select type and data available, the table data provider requires a multi dimensional array, this is available under this var path:
{var:f_read-data_soggetto_diario.Diario}
OR under this one:
{var:f_read-data_soggetti}
But the fields names are different in both cases of course!
Best regards
Max
If your main question got answered then please mark the answer using the button!​
​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!