Excellent, thanks a bundle grigri :-)
On Jun 9, 4:11 pm, grigri <[EMAIL PROTECTED]> wrote:
> Sorry for the confusion - for 'Model' I meant of course the proper
> model name:
>
> $tmp = $this->ProjectsProject->ProjectRelationshipType->find("all",
> array(
> "fields" => array("id", "CONCAT(name, '/', antonym) AS name"),
> "recursive" => -1,
> "order" => 'name'
> ));
>
> // uncomment the following line to see the raw structure
> // The parameters to Set::combine() will make sense once you see this
> // debug($tmp);
>
> $projectRelationshipTypes = Set::combine($tmp,
> '{n}.ProjectRelationshipType.id',
> '{n}.0.name'
> );
>
> On Jun 9, 4:03 pm, RichardAtHome <[EMAIL PROTECTED]> wrote:
>
> > Thanks again grigri :-)
>
> > My Code:
>
> > $tmp =
> > $this->ProjectsProject->ProjectRelationshipType->find("all",
> > array(
> > "fields" => array("id", "CONCAT(name, '/', antonym)
> > AS name"),
> > "recursive" => -1,
> > "order" => 'name'
> > ));
> > $projectRelationshipTypes = Set::combine($tmp,
> > '{n}.Model.id', '{n}.
> > 0.name');
>
> > Same view code as before.
>
> > Produces the following SQL:
>
> > SELECT `ProjectRelationshipType`.`id`, CONCAT(name, '/', antonym) AS
> > name FROM `project_relationship_types` AS `ProjectRelationshipType`
> > WHERE 1 = 1 ORDER BY `name` ASC
>
> > And returns the following array:
>
> > Array
> > (
> > [] => Predecessor/Successor
> > )
>
> > I have tried replacing 'Model.id' in Set::combine with
> > project_relationship_types and even 'xxx' with no discernable
> > difference!
>
> > I have also tried linking querying the ProjectRelationshipType model
> > directly but that gives the same output:
>
> > $tmp = $this->ProjectRelationshipType
>
> > On Jun 9, 3:17 pm, grigri <[EMAIL PROTECTED]> wrote:
>
> > > Both methods work fine for me. Post your exact code and I'll see if I
> > > can spot any errors.
>
> > > On Jun 9, 3:00 pm, RichardAtHome <[EMAIL PROTECTED]> wrote:
>
> > > > 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
-~----------~----~----~----~------~----~------~--~---