Hello, I've already asked on cakeqs.org but I'll try also here.
My case is: Order HABTM Product. In joining table orders_products I've
extra field - quantity. Now, when editing Order I can add Products and
enter quantitiy. Here is what I've done already:
In model Order:
public $hasAndBelongsToMany = array(
'Product' => array(
'className' => 'Product',
'joinTable' => 'orders_products',
'foreignKey' => 'order_id',
'associationForeignKey' => 'product_id',
'unique' => true,
'with' => 'OrdersProduct'
)
);
In model Product:
public $hasAndBelongsToMany = array(
'Order' => array(
'className' => 'Order',
'joinTable' => 'orders_products',
'foreignKey' => 'product_id',
'associationForeignKey' => 'order_id',
'unique' => true,
'with' => 'OrdersProduct'
)
);
I've created model for joining table OrdersProduct:
class OrdersProduct extends AppModel {
public $name = 'OrdersProduct';
public $validate = array(
'quantity' => array(
'numeric' => array('rule' => array('notempty'))
)
);
}
In orders editing view I've:
<?php echo $this->Form->input("Product.0.OrdersProduct.product_id",
array('label' => false, 'options' => $products)); ?>
<?php echo $this->Form->input("Product.0.OrdersProduct.quantity", array
('label' => false, 'class' => 'text')); ?>
Now in Orders controller try to save:
// Form processing
if (!empty($this->data)) {
$this->Order->OrdersProduct->set($this->data);
debug($this->Order->OrdersProduct->validates());
if ($this->Order->saveAll($this->data)) {
// Do some stuff
}
}
And $this->Order->OrdersProduct->validates() always returns TRUE, no
matter if I enter quantity or not. All the data saves perfect, only no
validation is problem. What I'm missing?
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