Hi there,

Thanks for your response. I should have clarified my situation. I have
a form for a related Region model (HABTM relationship) that calls
$this->Form->input('Reporter'); to show a multi select list of
Reporter records. I figured that adding a virtual name field called
"name" would auto-populate the select list with the reporters' names
like it does if the database already contains a field called "name".
As it happens, Cake does not auto populate the multi select list this
way when a virtual field called "name" is used.

Is there a way to have Cake display the virtual field as the select
menu's option names?

Thanks,
-Brian

On Dec 3, 3:42 pm, euromark <dereurom...@googlemail.com> wrote:
> you might be doing sth wrong
> how are you processing the result?
>
> because Reporter__name is correct so far.
> cake will then automatically merge the content of this key back to the
> Model result array with the key "name".
> and then it should be available with
> $result['Reporter']['name']
>
> since "name" and "title" have a special meaning (auto-displayField
> fields) it might also be related to this.
> did you try to use "full_name" as key to eliminate that cause yet?
>
> On 3 Dez., 21:21, aries <br...@allemana.com> wrote:
>
>
>
>
>
>
>
> > Hello,
>
> > I'm trying to use virtual fields with Cake 2.0 and am running into a
> > problem. I'm trying to populate a select input with values from a
> > table that has no `name` field. I'm setting a virtual field called
> > `name` with the first_name and last_name fields, but the menu is not
> > populating properly.
>
> > In my model I have simply:
>
> > public $virtualFields = array(
> >          'name' => "CONCAT(Reporter.first_name, ' ', Reporter.last_name)"
> > );
>
> > But when Cake does a find operation, the sql looks like this:
>
> > SELECT `Reporter`.`id`, `Reporter`.`first_name`,
> > `Reporter`.`last_name`, (CONCAT(`Reporter`.`first_name`, ' ',
> > `Reporter`.`last_name`)) AS `Reporter__name`
>
> > Calling the field alias `Reporter__name`, which then doesn't register
> > with select inputs. Is this expected behavior? Any recommended
> > solutions to my problem?
>
> > Thanks,
> > -Brian

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to