I have the following code in CakePHP 2:
$this->Order->id = 5;
$this->Order->saveAll(array(
'Order' => array(
'person_id' => $this->Session->read('Person.id'),
'amount' => $total,
'currency_id' => $code
),
'Lineitem' => $lineitems /* a correctly-formatted array */
));
I would expect this to update the row with the Primary Key of 5 in the Order
table and then insert the Lineitem
rows with an order_id of 5.
However, all it does is create a new row in Order
and then use the new id from the new Order
record to create the Listitem
rows.
Note: I'm only setting the ID as above for debugging purposes and to easily demonstrate this question. In my final code, I'll be checking to see if there's already a pending order with the current person_id
and doing $this->Order->id = $var;
if there is and $this->Order->create();
if there isn't.
In other words, sometimes I will want it to INSERT (in which case I will issue $this->Order->create();
) and sometimes I will want it to UPDATE (in which case I will issue $this->Order->id = $var;
). The test case above should produce an UPDATE but it's producing an INSERT instead.
Any idea what I am doing wrong here?