To do exactly what you want:

$citiesCombine = Set::combine($cities, '{n}.City.id', array('%s - %s',
'{n}.Country.name', '{n}.Country.name'));

But wouldn't you be better off generating option groups based on the
country? That's easy too:

$citiesCombine = Set::combine($cities, '{n}.City.id',
'{n}.Country.name', '{n}.Country.name');

Also bear in mind that if you're not using the $cities variable
anywhere else, you can use find('list') to generate the list in one
call:

[1] $citiesCombine = $this->City->find('list', array('recursive' => 0,
'order' => [...], 'fields' => array('City.id', array('%s - %s',
'Country.name', 'Country.name')));
or
[2] $citiesCombine = $this->City->find('list', array('recursive' => 0,
'order' => [...], 'fields' => array('City.id', 'Country.name',
'Country.name'));

(you just have to set the recursive because it defaults to -1, you
need 0 for the Country join)

On Feb 7, 1:06 pm, Josoroma <[EMAIL PROTECTED]> wrote:
> Im trying to generate a select list, but before the value Citiy.name i
> need to add Country.name like:
>
> Costa Rica - Heredia
> EEUU - New York
>
> $cities = $this->City->find('all', array('fields' => array('City.id',
> 'City.name', 'Country.name'), 'order'=>'City.country_id ASC'));
>
> My question is, how can i preppend the country name to the city name
> using combine?:
>
> $citiesCombine  = Set::combine($cities, '{n}.City.id',
> '{n}.Country.name');
>
> thanks in advance.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to