Re: Saving Associated Data that is an Array

2006-12-13 Thread themanfrombucharest

Hey,

All you need to do is call the create() model function to unset the
model id before each save in the loop, otherwise it gets set after the
first save.

On Dec 13, 5:33 pm, "Dave Rogers" <[EMAIL PROTECTED]> wrote:
> I have a report form that has a list of people who attended an event.
> When I try to save the attendees, the first one is added to the db, the
> rest attempt to update with the id of the event.
>
> here is an idea of the data:
>
> $this->data['event']=array(
>  'title'=>'title of event',
>  'date'=>'12/12/2006',
>  'attendees'=>array(
>   [0]=>array(
>'name'=>'sara lemming',
>'title'=>'queen bee'
>   ),
>   [1]=>array(
>'name'=>'joe schmoe',
>'title'=>'worker bee'
>   )
>  )
> )
>
> Before I save, I copy the attendees array to another variable
> ($attendees) and then unset the 'attendees' element from the data
> array.  The data array then saves ok.
>
> Then I do a 'foreach' on the $attendees array and save each to the
> proper model.  The first one is inserted into the db.  Then there is a
> 'select count' sql that is looking for the id of insert of the data
> array.  Then the rest of the $attendees try to update based on that id.
> 
> What am I doing wrong?


--~--~-~--~~~---~--~~
 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
-~--~~~~--~~--~--~---



Re: Saving Associated Data that is an Array

2006-12-13 Thread Samuel DeVore

$this->ModelName->create();
before your save.

On 12/13/06, Dave Rogers <[EMAIL PROTECTED]> wrote:
>
> I have a report form that has a list of people who attended an event.
> When I try to save the attendees, the first one is added to the db, the
> rest attempt to update with the id of the event.
>
> here is an idea of the data:
>
> $this->data['event']=array(
>  'title'=>'title of event',
>  'date'=>'12/12/2006',
>  'attendees'=>array(
>   [0]=>array(
>'name'=>'sara lemming',
>'title'=>'queen bee'
>   ),
>   [1]=>array(
>'name'=>'joe schmoe',
>'title'=>'worker bee'
>   )
>  )
> )
>
> Before I save, I copy the attendees array to another variable
> ($attendees) and then unset the 'attendees' element from the data
> array.  The data array then saves ok.
>
> Then I do a 'foreach' on the $attendees array and save each to the
> proper model.  The first one is inserted into the db.  Then there is a
> 'select count' sql that is looking for the id of insert of the data
> array.  Then the rest of the $attendees try to update based on that id.
>
> What am I doing wrong?
>
>
> >
>


-- 
==
S. DeVore
(the old fart) the advice is free, the lack of crankiness will cost you

--~--~-~--~~~---~--~~
 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
-~--~~~~--~~--~--~---



Saving Associated Data that is an Array

2006-12-13 Thread Dave Rogers

I have a report form that has a list of people who attended an event.
When I try to save the attendees, the first one is added to the db, the
rest attempt to update with the id of the event.

here is an idea of the data:

$this->data['event']=array(
 'title'=>'title of event',
 'date'=>'12/12/2006',
 'attendees'=>array(
  [0]=>array(
   'name'=>'sara lemming',
   'title'=>'queen bee'
  ),
  [1]=>array(
   'name'=>'joe schmoe',
   'title'=>'worker bee'
  )
 )
)

Before I save, I copy the attendees array to another variable
($attendees) and then unset the 'attendees' element from the data
array.  The data array then saves ok.

Then I do a 'foreach' on the $attendees array and save each to the
proper model.  The first one is inserted into the db.  Then there is a
'select count' sql that is looking for the id of insert of the data
array.  Then the rest of the $attendees try to update based on that id.

What am I doing wrong?


--~--~-~--~~~---~--~~
 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
-~--~~~~--~~--~--~---