sorry, it´s very early here, I meant: if($this->Order->save($this->data)) { $order_id = $this->Order->getLastInsertId();
foreach ($this->data[´OrderDetail´] as $order_detail) { $data = array(); $data[´OrderDetail´][íd´] = null; $data[´OrderDetail´][´order_id ´] = $order_id; $data[´OrderDetail´][´product_id ´] = $order_detail[´OrderDetail´][´product_id´]; $data[´OrderDetail´][´qty ´] = $order_detail[´OrderDetail´][´qty´]; $result = $this->Order->Orderdetail->save($data); } if ($result) { $this->Session->setFlash('The Order has been saved '.$order_id); } else { $this->Session->setFlash('Order details could not be saved for order id: '.$order_id); } } jon On 4/27/07, Jon Bennett <[EMAIL PROTECTED]> wrote: > hasMany´s are not saved automagically, try: > > if($this->Order->save($this->data)) > { > $order_id = $this->Order->getLastInsertId(); > > foreach ($this->data[´OrderDetail´] as $order_detail) > { > $data = array(); > $data[´OrderDetail´][íd´] = null; > $data[´OrderDetail´][´order_id ´] = $order_id; > $data[´OrderDetail´][´product_id ´] = $order_id; > $data[´OrderDetail´][´qty ´] = 20; > $result = $this->Order->Orderdetail->save($data); > } > > if ($result) > { > $this->Session->setFlash('The Order has been saved '.$order_id); > } > else > { > $this->Session->setFlash('Order details could not be saved for > order id: > '.$order_id); > } > } > > hth > > jon > -- jon bennett t: +44 (0) 1225 341 039 w: http://www.jben.net/ iChat (AIM): jbendotnet Skype: jon-bennett --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---