Output 3 - _cm_output_multi() [message #7618] |
Tue, 03 August 2021 16:14 |
htManager
Messages: 434 Registered: May 2014
|
Senior Member |
|
|
Hi Tony,
after installing the new version 2.19.0 I have some problems with two output3 patterns and the _cm_output_multi() function.
As you described in "dialog-types.html#output3" and in "functions-and-variables.html#notes._cm_output_multi" the _cm_output_multi($name, $inarray, $iteration) function holds in the $inarray ($fieldarray) the data of the parent record. I have the correct parent values in the _cm_changeConfig() and the _cm_initialise() method. But in the _cm_output_multi() method I have the value of the first record of the child table.
Do I have to change the values somewhere else?
|
|
|
|
Re: Output 3 - _cm_output_multi() [message #7620 is a reply to message #7618] |
Wed, 04 August 2021 05:22 |
AJM
Messages: 2368 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
I have just tested all the OUTPUT3 tasks that I have, and they are all working as expected. Logon to the demo system at https://www.radicore.org/demo/menu/logon.php then navigate to PROTO->Example System->List Person, select a person then press the "Invoice(PDF)" button and you will see that the selected PERSON record appears in $fieldarray. I don't know what you mean when you say that you are getting the first row of the child table as there is no child table defined for that pattern. It is only AFTER the _cm_output_multi() method is called that any child table is identified and accessed.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
Re: Output 3 - _cm_output_multi() [message #7622 is a reply to message #7621] |
Thu, 05 August 2021 04:57 |
AJM
Messages: 2368 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
If you are calling an OUTPUT3 pattern from a LIST2 screen then in the _cm_initialise() method of the OUTPUT3 task the $where argument should contain the primary key of the outer entity of the LIST2 screen while the $selection argument should contain the primary keys of any selected rows from the inner entity. Check that you are using the correct primary key.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
Re: Output 3 - _cm_output_multi() [message #7623 is a reply to message #7622] |
Thu, 05 August 2021 05:03 |
AJM
Messages: 2368 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
If it is your intention to have a separate page for each selected row from the inner entity then the _cm_output_multi() method will be called for each row. If you want some data from the parent record shown in the report title then your SELECT query should contain a JOIN to that table so that the data is available in each inner row.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
Re: Output 3 - _cm_output_multi() [message #7625 is a reply to message #7624] |
Thu, 05 August 2021 13:46 |
AJM
Messages: 2368 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
If you do not want a separate page for each selected row then you must ignore the contents of $selection in the _cm_initialise() method. The $where string should contain the primary key of the outer entity in the LIST2 screen. This string should also have been used as the foreign key for the inner entity of the LIST2 screen. The $selection string should only be populated if you marked any of the inner rows in the LIST2 screen as selected.
The two strings should NOT be the same. If they are you need to debug the childform() function inside file include.session.inc where it calls $dbobject->getWhere().
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
Re: Output 3 - _cm_output_multi() [message #7627 is a reply to message #7626] |
Sat, 07 August 2021 05:16 |
AJM
Messages: 2368 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
The $where argument in the _cm_initialise() method should contain the primary key of a single row in the outer entity of the parent LIST2 screen. The child OUTPUT3 task should then read that single row, then call the _cm_output_multi() method so that it can add additional rows to the output. The $fieldarray argument in the _cm_output_multi() method should contain the data for the single selected row. It should be called multiple times with different zone names in the $name argument. Once all the zones have been processed for the current row it should then look for the next row, but there should be no next rows.
What the the names of the two tables? What are their primary keys? If everything works fine until the last multi zone then what code do you have for that zone? What record is shown in the $fieldarray argument?
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
Re: Output 3 - _cm_output_multi() [message #7629 is a reply to message #7628] |
Sun, 08 August 2021 06:00 |
AJM
Messages: 2368 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
I have just run a test on my development system where I go to a LIST2 screen and press a navigation button to activate a child task, then in the child task I look to see what values are passed in $where and $selection. As expected the $where string contains a single primary key for the outer entity in the LIST2 screen while $selection contains a list of zero or more primary keys for whatever rows were marked as selected in the inner entity of the LIST2 screen.
If you are saying that the $where string identifies multiple rows instead of a single row then there must be something in your code which is overriding the framework's default behaviour.
What is the primary key of your outer entity? What value is being extracted by the call to the getWhere() function inside the childForm() function within script include.session.inc? This happens within the parent screen before the child screen is called, so this would be where the wrong value is being obtained.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
|
Re: Output 3 - _cm_output_multi() [message #7632 is a reply to message #7631] |
Tue, 10 August 2021 04:33 |
AJM
Messages: 2368 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
You are confusing me. You start with a LIST2 screen which has two tables, OUTER and INNER. It contains one occurrence of the OUTER table and multiple occurrences of the INNER table. When you press the navigation button which activates the OUTPUT3 task it passes down two variables - $where and $selection. $where will contain the primary key (or its foreign key equivalent) of OUTER while selection will contain the primary keys of any of the INNER rows which were marked as selected. In your OUTPUT3 task what is the starting table? What additional tables are you accessing in the _cm_output_multi() method?
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
Re: Output 3 - _cm_output_multi() [message #7634 is a reply to message #7633] |
Wed, 11 August 2021 05:04 |
AJM
Messages: 2368 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
You say that when the OUTPUT3 task is activated and the _cm_initialise() method is called that both the $where and $selection arguments contain the primary key fields and values from the inner entity of the LIST2 screen, which is orga_spiele_anwesenheit. This is not correct. The $where argument should contain the $where string that went into the inner entity before it performed its own $inner->getData($where) and the $selection argument will contain the primary keys of those inner rows which were selected after the screen was displayed.
If the field names of the outer table's primary key are different from the field names of the inner entity's foreign key then it would have been necessary to convert them before they could be used in $inner->getData(). It is these foreign key values which would have been extracted from the LIST2 screen and passed as the $where argument to the child OUTPUT3 task.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
Re: Output 3 - _cm_output_multi() [message #7637 is a reply to message #7635] |
Thu, 12 August 2021 05:04 |
AJM
Messages: 2368 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
When a navigation button is pressed the $where and $selection strings which are passed to the next task are obtained from the inner table of the current task. The $where string is what was used as the $where argument in the _cm_pre_getData() method while the $selection string is constructed from all those rows from the inner table which were marked as selected.
Note that if the names of the primary key fields in the outer table of the LIST2 screen are different from the corresponding foreign key names of the inner table then these will have to be adjusted if you wish to reconstruct the primary key of the outer table. This adjustment can be done in either the _cm_initialise() method of the next task or at the start of the _cm_pre_getData() method.
My usual practice is the use the same field names in both the primary and foreign keys, with the only exception being when there is more than one relationship between the two tables, or when a table is related to itself.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
Re: Output 3 - _cm_output_multi() [message #7639 is a reply to message #7638] |
Sat, 14 August 2021 04:56 |
AJM
Messages: 2368 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
You should also be aware that in patterns such as LIST2 and LIST3 where there are multiple tables in a parent-child relationship that the script will use the getForeignKeyValues($parent, $child) function to extract the primary key from the parent table so that it can be passed down to the child. If the relationship in the Data Dictionary identifies that the field names in the foreign key of the child are different from the field names of the primary key in the parent then this function will return the foreign key names instead of the primary key names, which means that you should not have to make any manual adjustments in the child class.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
|
Re: Output 3 - _cm_output_multi() [message #7648 is a reply to message #7647] |
Tue, 31 August 2021 04:52 |
AJM
Messages: 2368 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
It should not be necessary to change the names of the primary key fields in the child table, only the foreign key fields, unless the two are the same.
If you have described the relationship between the parent and child tables in the Data Dictionary then this should have identified the names of the foreign key fields which are related to the primary key fields in the parent table. In this case the LIST2/3/4 patterns, which use the getForeignKeyValues() function, should automatically convert the field names for you.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
Re: Output 3 - _cm_output_multi() [message #7651 is a reply to message #7650] |
Fri, 03 September 2021 04:48 |
AJM
Messages: 2368 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
If the parent table has a compound primary key then any child table must have a compound foreign key where every column within the foreign key is matched to the corresponding column in the primary key.
In your above example the columns A1_id, A2_id, A3_id in the child table would be the foreign key with U_id being part of the primary key. In this case you should not have to take any action as the components of the foreign key have exactly the same names as the components of the primary key, so no swapping of column names is necessary.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
|
|
|
|
|