Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE » How To » table related to itself
table related to itself [message #841] Wed, 23 May 2007 10:55 Go to next message
interop is currently offline  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 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2347
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.


Re: table related to itself [message #843 is a reply to message #842] Wed, 23 May 2007 11:50 Go to previous messageGo to next message
interop is currently offline  interop
Messages: 45
Registered: October 2006
Member
You're right, I'm having difficulty explaining but your assumptions are correct.

I'll look into the popupReturn for setting the parent. thanks

How about when parent_equipment_id is null? When I read an equipment entry that has no parent, parent_equipment_id is displayed as the current model of equipment. It should be empty. Is this related to the popupReturn also?
Re: table related to itself [message #844 is a reply to message #843] Wed, 23 May 2007 12:17 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2347
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?


Re: table related to itself [message #845 is a reply to message #841] Wed, 23 May 2007 13:19 Go to previous messageGo to next message
interop is currently offline  interop
Messages: 45
Registered: October 2006
Member
I stepped through and don't see anything wrong with getting the data. The xml file (equipment(upd1).php.xml) shows parent_equipment_id is null.

<parent_equipment_id size="10" control="popup" foreign_field="model" task_id="task#iol_equipment(popup)"></parent_equipment_id>

I see that equipment_id is not converted back to parent_equipment_id in popupReturn() which indicates my foreign_field settings are incorrect. Could my foreign field settings be causing the display problem as well?
Re: table related to itself [message #846 is a reply to message #841] Wed, 23 May 2007 13:26 Go to previous message
interop is currently offline  interop
Messages: 45
Registered: October 2006
Member
Yup, that's it. I changed my foreign field settings and it seems to be working. Sorry for the hassle.
Previous Topic: Display field from Related table 2
Next Topic: Using dropdown
Goto Forum:
  


Current Time: Fri Apr 19 16:23:03 EDT 2024

Total time taken to generate the page: 0.01161 seconds