I am trying to save an order, and the products in the order.
The order is being saved, but the products are not.
I have an orders table and a
You can use the previous solution, BUT if have also to update the parent tables, you must unbind. In my example I have a table Order and a table Product. I needs to put two extra fields for every product with respect to the Order.id . See this example:
$this->Order->create();
$this->Order->unBindModel(array('hasAndBelongsToMany'=>array('Product')));
$f = $this->Order->save($this->data,false);
/* Save extra columns in HABTM TABLE */
$this->Order->bindModel(array('hasMany'=>array('OrderProduct')));
$q = array();
if (!isset($this->data['Product']))
{
$v = false;
}
else
{
$v =true;
for($i=0;$idata['Product']);$i++)
{
$this->data['OrderProduct'][$i]['order_id'] = $this->Order->getLastInsertID();
$this->data['OrderProduct'][$i]['product_id'] = $this->data['Product'][$i];
$this->data['OrderProduct'][$i]['quantity'] = $this->data['quantity'][$i];
$this->data['OrderProduct'][$i]['state_id'] = $this->data['State'][$i];
}
}
$s = $this->Order->OrderProduct->saveAll($this->data['OrderProduct']);