Cakephp 3 saving array of data

3.4k Views Asked by At

Is there a function like it was in cakephp 2 saveAll that saves array of data? I want to save the data just once not every time inside a foreach loop.

foreach($rezults as $rezult) {
   $data=$this->Products->newEntity();
   $data['id'] = $rezult->id;
   $data['name'] = $rezult->name;
   if($this->Products->save($data)){
   }
}

this is the code that I'm using to save an array of data. is there another way?

1

There are 1 best solutions below

1
On BEST ANSWER

No, there isn't, if you need such a function, then you have to create it on your own, which should be a pretty easy thing to do though, just add a method to your table class that saves data in a loop (ideally in a transaction probably) - if you need it in all tables, put it in a base class and make your tables extend it.

See also