oops, spoke too soon...

Method 1: Works, but only populates the array with 1 row (the SQL it
produces is correct)

Method 2: Fails with the following error:

Warning (2): vsprintf() [function.vsprintf]: Too few arguments [CORE
\cake\libs\set.php, line 357]


On Jun 9, 1:14 pm, RichardAtHome <[EMAIL PROTECTED]> wrote:
> Many thanks grigri :-)
>
> I think I'll be opting for method 1 (less code, and I feel the
> concatenation *should* happen in the database layer)
>
> I was using version 2.1 RC1 btw (I can't believe I forgot to include
> that in my original post >.< )
>
> On Jun 9, 12:40 pm, 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 [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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to