Saturday, October 31, 2009

Re: Model->saveAll() return value issue

Here is a little more details about this:
when saveAll() is called with 'validate'=>'first' and
'atomic'=>'false' returned array is with double number of elements
than desired to store elements (if I try to save 5 elements, returned
array contains 10). I suspect that is for validation.
When saveAll() is called with 'validate'=>'only' returned array is as
expected - for every element that I want to save returns 0 or 1
according to validation.


On Oct 29, 4:14 pm, senser <nikolay.engyo...@gmail.com> wrote:
> There is another strange (in my opinion) behavior ofsaveAll() - as
> you can see in my previous post in second parameter I use
> 'validate'=>'first' to validate all records before save any (as is
> described in manual and api).
> But even if any of array elements doesn't pass validation, other
> elements are stored as well.... Is this a bug or I'm missing something
>
> On Oct 29, 12:52 pm, senser <nikolay.engyo...@gmail.com> wrote:
>
> > Hello guys,
>
> > I'm trying to use Model->saveAll() in one of my projects for saving
> > multiple model records (not associations). Hera is structured data I
> > try to save:
>
> > Array
> > (
> >     [Email] => Array
> >         (
> >             [0] => Array
> >                 (
> >                     [email_id] => 8
> >                     [employee_mailbox_id] => 77
> >                     [notes] =>
> >                 )
>
> >             [1] => Array
> >                 (
> >                     [email_id] => 8
> >                     [employee_mailbox_id] => 5
> >                     [notes] =>
> >                 )
>
> >             [2] => Array
> >                 (
> >                     [email_id] => 8
> >                     [employee_mailbox_id] => 1
> >                     [notes] =>
> >                 )
>
> > )
>
> > As you can see model name is "Email" and I want to store three records
> > in corresponding table at once with following controller code:
> > $this->Email->create($data['Email']);                     $result=$this->Email->saveAll
> > ($data['Email'], array('validate'=>'first', 'atomic'=>false));
>
> > My confusion is caused by the return value otsaveAllfunction - it is
> > array containing 5 elements but not 3. Elements with value 1 for
> > succeeded elements and 0 for unsuccessful stored elements suppose.
>
> > Am I wrong or missing something and how can I retrieve what elements
> > are stored successfully and what are failed.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: