This suggestion by Jeremy looks all right: $states = $this->Employee->State->find('list'); $this->set(compact('states'));
My hint would be to change your database schema to state: id, name or state: id, title as state: id, state is redundant anyway. The magic that will appear is cake auto detecting name (or title) as the display field to use with find('list'). If you do not want to change the schema you can use var $displayField. See the book. Regards ionas On Jan 4, 11:36 pm, Guran <guran.banga...@gmail.com> wrote: > I am a new baker and I am stuck in the dough. I am trying to insert a > option/select drop down but cannot get the field I need to show in the > drop down > I have the following tables: > > CREATE TABLE IF NOT EXISTS `employees` ( > `id` int(11) unsigned NOT NULL AUTO_INCREMENT, > `state_id` int(11) unsigned NOT NULL, > `name` varchar(50) NOT NULL, > `email` varchar(30) DEFAULT NULL, > PRIMARY KEY (`id`), > UNIQUE KEY `employees.state_id` (`state_id`) > ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; > > CREATE TABLE IF NOT EXISTS `states` ( > `id` int(11) unsigned NOT NULL AUTO_INCREMENT, > `state` varchar(2) NOT NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=51 ; > > INSERT INTO `states` (`id`, `state`) VALUES > (1, 'AL'), > (2, 'AR'), > (3, 'AZ'), > (4, 'CA'), > (5, 'CO'), > (6, 'CT'), > (7, 'DC'), > (8, 'DE'); > > The following two models are generated through console tool cake bake > model using the default options provided. > > class State extends AppModel { > var $name = 'State'; > var $belongsTo = array( > 'Employee' => array( > 'className' => 'Employee', > 'foreignKey' => 'state_id', > 'conditions' => '', > 'fields' => '', > 'order' => '' > ) > ); > > } > > class Employee extends AppModel { > var $name = 'Employee'; > var $belongsTo = array( > 'State' => array( > 'className' => 'State', > 'foreignKey' => 'state_id', > 'conditions' => '', > 'fields' => '', > 'order' => '' > ) > ); > > } > > I would like to show the "states.state" field but all I get is the > "states.id" field in the dropdown. Where have I gone wrong? > > Any help is appreciated! Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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 cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en