table related to itself [message #841] |
Wed, 23 May 2007 10:55 |
interop
Messages: 45 Registered: October 2006
|
Member |
|
|
I have a table (equipment) which is related to itself. In the detail view (read or update) the parent_equipment_id is always filled in with the current equipment's model. Even if the parent_equipment_id is null in the db and xml.
I've stepped through the code and parent_equipment_id is in fact null. I have other tables that are related to themselves which work fine as dropdowns. I just can't seem to get this one working as a popup.
I've read the following:
http://www.tonymarston.net/php-mysql/infrastructure-faq.html #faq27
http://www.tonymarston.net/php-mysql/infrastructure-faq.html #faq38c
Here are some of the settings in my files can you see something wrong?
#equipment.dict.inc
$fieldspec['parent_equipment_id'] = array('type' => 'integer',
'size' => 10,
'minvalue' => 0,
'maxvalue' => 4294967295,
'control' => 'popup',
'task_id' => 'iol_equipment_snr(popup1)',
'foreign_field' => 'model');
$this->child_relations[] = array('child' => 'equipment',
'alias' => 'equipment_jnr',
'type' => 'RES',
'fields' => array('equipment_id' => 'parent_equipment_id'));
$this->parent_relations[] = array('parent' => 'equipment',
'alias' => 'equipment_snr',
'parent_field' => 'parent_equipment_id AS parent_id',
'fields' => array('parent_equipment_id' => 'equipment_id'));
#equipment.detail.screen.inc
$structure['main']['fields'][] = array('parent_equipment_id' => 'Parent Equipment');
#equipment(upd1).php.xml
<parent_equipment_id size="10" control="popup" foreign_field="model" task_id="task#iol_equipment_snr(popup1)"></parent_equipment_id >
equipment_snr.class.inc just extends equipment without modifications.
thanks
|
|
|
Re: table related to itself [message #842 is a reply to message #841] |
Wed, 23 May 2007 11:30 |
AJM
Messages: 2371 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
You haven't explained very well what your problem actually is, so I'll have to take a guess.
You have a table called 'equipment' which contains a primary key called 'equipment_id'. It also contains a non-key field called 'parent_equipment_id' which is related back to 'equipment_id' on the same table.
In your detail screen you are using a popup control to provide a value for 'parent_equipment_id'.
I am assuming that the popup works correctly in that it displays entries and allows you to choose one, but after returning to the detail screen the chosen entry is not shown.
If you think about it the problem is quite straight forward - the popup is passing back a selection string like "equipment_id='abc'", but when this is received you want the value inserted into 'parent_equipment_id' instead. If this translation from 'equipment_id' to 'parent_equipment_id' is not being performed then the popup selection is being lost.
You can perform this translation manually in the _cm_popupReturn() method as shown in http://www.tonymarston.net/php-mysql/functions-and-variables .html#notes._cm_popupreturn, but if you are using the latest version of Radicore you may find that this can be done automatically by the code inside the popupReturn() method within 'std.table.class.inc'.
I hope this helps.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
Re: table related to itself [message #844 is a reply to message #843] |
Wed, 23 May 2007 12:17 |
AJM
Messages: 2371 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
No. The popupreturn() method is only called when returning from a popup, not when reading the data for initial display.
If a value for 'parent_equipment_id' is being incorrectly displayed you will need to step through your code with a debugger to see where the wrong value is being picked up. Is the sql SELECT statement that is being constructed at fault? Do you have any custom code that is accidentally picking up the wrong value?
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
|