It only happens automagically if you conform to the standards - which
you're not because of the legacy naming conventions.

Simply change your input like so:

echo $this->Form->input('id_supplier', array('options' =>
$suppliers));

And Bob's your uncle!

hth
grigri

On Jul 22, 1:47 am, guvilla <[email protected]> wrote:
> >>> database tables
>
> CREATE TABLE IF NOT EXISTS `product` (
>   `id_product` int(10) unsigned NOT NULL AUTO_INCREMENT,
>   `id_supplier` int(10) unsigned DEFAULT NULL,
>   `id_manufacturer` int(10) unsigned DEFAULT NULL,
>   `id_tax` int(10) unsigned NOT NULL,
>   `id_category_default` int(10) unsigned DEFAULT NULL,
>   `id_color_default` int(10) unsigned DEFAULT NULL,
>   `on_sale` tinyint(1) unsigned NOT NULL DEFAULT '0',
>   `ean13` varchar(13) DEFAULT NULL,
>   `ecotax` decimal(17,2) NOT NULL DEFAULT '0.00',
>   `quantity` int(10) unsigned NOT NULL DEFAULT '0',
>   `price` decimal(20,6) NOT NULL DEFAULT '0.000000',
>   `wholesale_price` decimal(20,6) NOT NULL DEFAULT '0.000000',
>   `reduction_price` decimal(17,2) DEFAULT NULL,
>   `reduction_percent` float DEFAULT NULL,
>   `reduction_from` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
>   `reduction_to` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
>   `reference` varchar(32) DEFAULT NULL,
>   `supplier_reference` varchar(32) DEFAULT NULL,
>   `location` varchar(64) DEFAULT NULL,
>   `weight` float NOT NULL DEFAULT '0',
>   `out_of_stock` int(10) unsigned NOT NULL DEFAULT '2',
>   `quantity_discount` tinyint(1) DEFAULT '0',
>   `customizable` tinyint(2) NOT NULL DEFAULT '0',
>   `uploadable_files` tinyint(4) NOT NULL DEFAULT '0',
>   `text_fields` tinyint(4) NOT NULL DEFAULT '0',
>   `active` tinyint(1) unsigned NOT NULL DEFAULT '0',
>   `indexed` tinyint(1) NOT NULL DEFAULT '0',
>   `date_add` datetime NOT NULL,
>   `date_upd` datetime NOT NULL,
>   PRIMARY KEY (`id_product`),
>   KEY `product_supplier` (`id_supplier`),
>   KEY `product_manufacturer` (`id_manufacturer`),
>   KEY `id_tax` (`id_tax`),
>   KEY `id_category_default` (`id_category_default`),
>   KEY `id_color_default` (`id_color_default`),
>   KEY `date_add` (`date_add`)
> ) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
>
> CREATE TABLE IF NOT EXISTS `supplier` (
>   `id_supplier` int(10) unsigned NOT NULL AUTO_INCREMENT,
>   `name` varchar(64) NOT NULL,
>   `date_add` datetime NOT NULL,
>   `date_upd` datetime NOT NULL,
>   PRIMARY KEY (`id_supplier`)
> ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
>
> >>> supplier.php
>
> <?php
> class Supplier extends AppModel {
>         var $name       = 'Supplier';
>         var $useTable   = 'supplier';
>         var $primaryKey = 'id_supplier';
>
>         var $hasMany = array('Product' => array(
>                                          'className'  => 'Product',
>                                                  'foreignKey' => 
> 'id_supplier',
>                                                  'dependent'  => true,)
>                                         );
>
> }
>
> ?>
>
> >>> product.php
>
> <?php
> class Product extends AppModel {
>         var $name       = 'Product';
>         var $useTable   = 'product';
>         var $primaryKey = 'id_product';
>
>         var $belongsTo = array(
>                                         'Supplier' => array(
>                                                 'className' => 'Supplier',
>                                                 'foreignKey' => 'id_supplier',
>                                                 'conditions' => '',
>                                                 'fields' => '',
>                                                 'order' => ''));
>
> }
>
> ?>
>
> >>> products_controller.php (just showing add method)
>
> (...)
>         function add() {
>                 if (!empty($this->data)) {
>                         $this->Product->create();
>                         if ($this->Product->save($this->data)) {
>                                 $this->Session->setFlash(__('The product has 
> been saved', true));
>                                 $this->redirect(array('action' => 'index'));
>                         } else {
>                                 $this->Session->setFlash(__('The product 
> could not be saved.
> Please, try again.', true));
>                         }
>                 }
>                 $suppliers = $this->Product->Supplier->find('list');
>                 $this->set(compact('suppliers'));
>         }
> (...)
>
> >>> add.ctp
>
> <div class="products form">
> <?php echo $this->Form->create('Product');?>
>         <fieldset>
>                 <legend><?php __('Add Product'); ?></legend>
>         <?php
>                 echo $this->Form->input('id_product');
>                 echo $this->Form->input('id_supplier');
> (...)
>
> Why it doesn't show Product form with Suppliers as combobox?

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 [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

Reply via email to