On Fri, Apr 15, 2011 at 10:45 AM, Uriel Juliatti <uriel.juliattiva...@gmail.com> wrote: > Hey everybody > > I'd like to know how to display a list of > Manufacturers (associated with Cars) in a combobox when I create cars. > > My Mysql query returns it: > > SELECT `Carro`.`id`, `Carro`.`fabricante_id`, `Carro`.`nome`, > `Carro`.`modelo`, `Carro`.`blindado`, `Carro`.`cor`, `Carro`.`ano`, > `Carro`.`preco`, `Fabricante`.`id`, `Fabricante`.`nome` FROM `carros` > AS `Carro` LEFT JOIN `fabricantes` AS `Fabricante` ON > (`Carro`.`fabricante_id` = `Fabricante`.`id`) WHERE 1 = 1 > > // Where fabricante = Manufacturer and Carro = Car. > > My models are: > > models/carro.php: > class Carro extends AppModel > { > var $name = "Carro"; > var $belongsTo = 'Fabricante'; > } > > models/fabricante.php: > > class Fabricante extends AppModel > { > var $name = "Fabricante"; > var $hasMany = array('Carro' => array( > 'className' => 'Carro', > 'foreignKey' => 'fabricante_id', > 'dependent'=> true > ) > ); > } > > Does anyone have any idea how to display the Manufacturers into a > combobox at Cars 'add' view?
public function add() { if (!empty($this->data)) { // attempt to save } $this->set( 'fabricantes', $this->Carro->Fabricante->find('list') ); } echo $this->Form->select('Carro.fabricante_id', $fabricantes); -- 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