It looks like your error message will only show if the save on the
*last* order_detail fails, since $result is reset with each iteration
of the loop. This action probably should use transaction processing
(commit/rollback support).

Also, instead of setting the id field to null in each iteration, I
think it's prefered to use "create" before each save:

$this->Order->Orderdetail->create();

Probably does the same thing, but since it's there, it must be the
better way...I hear these cake guys are smart and they wouldn't put it
in there if there was no good reason :)



On Apr 27, 2:29 am, "Jon Bennett" <[EMAIL PROTECTED]> wrote:
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to