You haven't gone wrong, as such - because the params to CONCAT, and
similar functions, can be from multiple tables in the query, they have
to go in their own slot in the results array.
There are loads of threads about dealing with this issue (search 'SQL
aggregate functions' or similar), but some ideas:
- post process the data in the afterFind callback, so it seamlessy
appears in your preffered format; this could perhaps be generalised to
work for all models.
- Use an SQL view to pretend this, and other fields, really exist in
the table - you can switch back and forth between the table and the
view if necessary.
On Apr 11, 5:24 pm, PeteWilliams <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I've only been baking a couple days, so I'm probably missing something
> obvious here! I've got a users table which has first names and second
> names, but for my listing display on the index action, i want to
> include their full names. Due to the generic way i've implemented by
> listing element, I basically want to have a property in the model
> called 'name' which contains the full name.
>
> I'd hoped that by doign this in the controller it would do that:
>
> $this->{$this->modelClass}->findAll( null, "*, CONCAT(first_name, ' ',
> surname) AS name" )
>
> That does get the name, but instead of adding it to the 'User' keyed-
> array, it adds it to a sibling array of key '0'.
>
> Anyone care to point our where I've gone wrong?
>
> Cheers
>
> Pete
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---