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

Home » RADICORE » How To » get calculated field from parent table
Re: get calculated field from parent table [message #1948 is a reply to message #1947] Mon, 09 February 2009 17:29 Go to previous messageGo to previous message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
Let's see if I've got this straight - you have a table (let's call it 'x') with a foreign key called 'staff_id' which points to an entry on the 'staff' table. The 'staff' table contains a foreign key called 'person_id' which points to an entry on the 'person' table. The 'person' table contains a column called 'person_name'.

This means that when you read a row from table 'x' you want to read table 'staff' then table 'person' in order to fetch the 'person_name' column.

In this case the relationship between the 'person' table and the 'staff' table should be defined in the dictionary so that 'person_name' is the parent field. This means that when an occurrence of the 'staff' table is retrieved the framework will automatically JOIN to the parent 'person' table and bring back the value for 'person_name'.

In your _cm_getExtraData() method for table 'x' you will need code simiar to the following:
if (empty($fieldarray['person_name']) AND !empty($fieldarray['staff_id'])) }
    $dbobject =& singleton::getInstance('staff');
    $data = $dbobject->getData("staff_id='{$fieldarray['staff_id']}'");
    $fieldarray['person_name'] = $data[0]['person_name'];
} // if

Try it and see.


 
Read Message
Read Message
Read Message
Read Message
Previous Topic: How to make a list2 on a non existing child table
Next Topic: Dynamically generate pdf layout?
Goto Forum:
  


Current Time: Fri Nov 29 07:33:47 EST 2024

Total time taken to generate the page: 0.01219 seconds