Access non key data from parent table [message #1587] |
Sun, 31 August 2008 06:11 |
gpatti
Messages: 283 Registered: August 2008
|
Senior Member |
|
|
I am trying to use the ADD4 transaction from a LIST2 transaction to add multiple rows of data to a table based on a parent record selected. However, to build the select clause for the data I want to add I need to know the value of a field from the selected parent row that is not a key. I understand that only the key fields are passed in context to the ADD4 (child) transaction.
How can I either pass the non-key data to the child ADD4 transaction or access the parent table to retrieve it from the child transaction?
Thanks
Graham
|
|
|
Re: Access non key data from parent table [message #1588 is a reply to message #1587] |
Sun, 31 August 2008 09:20 |
AJM
Messages: 2368 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
When you say that "only the key fields are passed in context to the child transaction" you are describing the default behaviour, but like most aspects of the Radicore framework this default can be overridden.
The string which is inserted into $selection by the parent task and then passed to the child task is constructed by taking a list of field names (by default the primary key) then combining it with the values from the selected record(s) to form a string in the format:
(field1='value1a' AND field2='value2a') OR (field1='value1b' AND field2='value2b')
This list of field names is initially populated by using the getPkeyNames() method, but it can be modified by inserting code into the _cm_getPkeyNames() method of the relevant table class.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
Re: Access non key data from parent table [message #1634 is a reply to message #1633] |
Thu, 11 September 2008 11:54 |
AJM
Messages: 2368 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
This is where you really ought to be using a debugger to see exactly what is going on instead of making wild guesses.
When you are in a LIST2 task, make one or more selections in the INNER (child) area and then press a navigation button, this is what happens:
(1) The LIST2 controller calls the childForm() function.
(2) This function detects that $_POST['select'] is not empty, so it calls the getPkeyArray() method on the INNER object.
(3) This function calls $object->getPkeyNames() to get the list of primary key felds as defined in the data dictionary.
(4) It then calls $object->_cm_getPkeyNames() to allow this list of field names to be customised.
(5) It then loops through $object->fieldarray, and for every row which was selected it constructs an associative array using the list of field names obtained previously.
(6) This associative array is then converted into a string which is passed to the task associated with the navigation button.
If your _cm_getPkeyNames() method is not being called then have you checked that you put it in the right class?
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
Re: Access non key data from parent table [message #1636 is a reply to message #1635] |
Thu, 11 September 2008 13:36 |
AJM
Messages: 2368 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
The selection from the INNER entity is passed to the child task via the $selection string, which can be customised using the _cm_getPkeyNames() method. The $where string is also extracted from the same object and passed in the $where string, which can be customised using the _cm_getWhere() method. If no selection is made then $selection will be set to $where.
You therefore need to put some code in the _cm_getWhere() method if you are not making any selections from the INNER entity.
I have tried navigating from a LIST2 to a ADD4 and I see the $where string correctly passed to the ADD4 task where it is passed to the initialise() and _cm_initialise() methods. It is still there when it is passed to the getInitialDataMultiple() method, but is converted into an associative array before being passed to the _cm_getInitialDataMultiple() method. There is nothing in the standard code which loses the contents of $where. Where does it happen in your code?
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
|
Re: Access non key data from parent table [message #1639 is a reply to message #1638] |
Thu, 11 September 2008 14:58 |
AJM
Messages: 2368 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
You are confusing me. You said that $where was being initialised when in fact it is passed to the initialise() method, which is something else entirely.
If the input string to initialise() contains the values that you want, but some are being filtered out with the filterWhere() function, then you are correct in saying that the list of fields which should not be filtered out can be customised with the _cm_filterWhere() method. When you step through with your debugger the comments I have in my code should explain what each function does.
When you report a problem such as this it is important to identify where you are having the problem - in the parent task or the child task - and whether you are having a problem putting values into the selection criteria *before* they are passed to the child task, or having values filtered out *during* the processing of the child task. It is no good me investigating what is going on in the processing of the parent task if the problem actually lies in the processing of the child task.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|