iS THIS IN VERSION 1.1 ?

Can the concat query be used wirth $this->Model->generateList(); ?

On Jun 9, 7:40 am, grigri <[EMAIL PROTECTED]> wrote:
> Currently, Model::find('list') only allow for simple fields to be
> used. Thw workaround is to use find('all') and Set::combine().
>
> Method 1 [perform concat in SQL] :
>
> $tmp = $this->Model->find('all', array(
>   'fields' => array('id', 'CONCAT(name, \'/\', antonym) AS
> something'),
>   'recursive' => -1,
>   'order' => 'name'
> ));
> $ret = Set::combine($tmp, '{n}.Model.id', '{n}.0.something');
>
> Method 2 [perform concat in PHP]
>
> $tmp = $this->Model->find('all', array(
>   'fields' => array('id', 'name', 'antonym'),
>   'recursive' => -1,
>   'order' => 'name'
> ));
> $ret = Set::combine($tmp,
>   '{n}.Model.id',
>   array(
>     '%s / %s', // Format string
>     '{n}.Model.name',
>     '{n}.Model.antonym'
> ));
>
> Working on a patch to allow more complicated expressions in
> find('list'), but it's not as easy as you might think!
>
> On Jun 9, 11:57 am, RichardAtHome <[EMAIL PROTECTED]> wrote:
>
> > Hi all :-)
>
> > I'm trying to populate a drop down list using Model->find('list')
> > where the display field is a concatenation of two other fields in the
> > model.
>
> > I am using the following code:
>
> > $projectRelationshipTypes = 
> > $this->ProjectsProject->ProjectRelationshipType->find('list', 
> > array("fields"=>array("id",
>
> > "concat(name, ' / ', antonym) as name"), "order"=>"name"));
>
> > Which produces the following (correct) SQL:
>
> > SELECT `ProjectRelationshipType`.`id` , concat( name, ' / ', antonym )
> > AS name
> > FROM `project_relationship_types` AS `ProjectRelationshipType`
> > WHERE 1 =1
> > ORDER BY `name` ASC
>
> > This query is correctly returning the two rows I would expect with two
> > fields (id, name)
>
> > My problem is that the find() is returning an empty array and the drop
> > down list is blank :-(
>
> > What am I doing wrong?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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