0

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?

Hamza Zafeer
  • 2,360
  • 13
  • 30
  • 42
Nodos
  • 85
  • 1
  • 10

1 Answers1

2

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

ndm
  • 59,784
  • 9
  • 71
  • 110
  • As of version 3.2.8, there is a [saveMany](https://book.cakephp.org/3.0/en/orm/saving-data.html#saving-multiple-entities) function for this. – Greg Schmidt Jan 29 '18 at 00:31