If I understand your question properly, this might help...
I have the following data:
Organizations hasMany Locations.
Locations hasMany Contacts. In my select boxes, when I am choosing
the Location that a contact belongs to, I needed to be able to see both
the Organization name and the Location name in the select box. Here is
what I did to accomplish that:
in my Locations model I am using the afterFind function:
function afterFind($results) {
foreach ($results as $key => $val) {
if (!empty($val['Location']['organization_id']))
{
$organization = $this->query("SELECT name FROM
organizations WHERE
id=".$val['Location']['organization_id']);
$results[$key]['Location']['fullname'] =
$organization[0]['organizations']['name'].' -
'.$val['Location']['name'];
}
}
return $results;
}
Next, in my Contacts controller I use the following:
$this->set('locationArray',$this->Contact->Location->generateList(null,null,null,'{n}.Location.id','{n}.Location.fullname'));
I am new to Cake, so their may be an easier way that I don't know
about, but this works for me.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---