• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Insert multiple records with entities

#1
Hello!

I am trying to insert multiple values that are saved in an entity, the problem is that when I try to save with the function model->save (), it sends an error because it seems not ready to accept entity objects

I am trying to do it as follows


PHP Code:
$batch = [];
foreach ($this->request->getVar('name_option') as $key => $value) {
  $variantOption = new VariantOption();     
  $variantOption
->name = $this->request->getVar('name_option')[$key];
  $variantOption->price = $this->request->getVar('price_option')[$key];
  $variantOption->price_discount = $this->request->getVar('discount_option')[$key];
  $batch[] = $variantOption;
}
$this->modelVariantOptions->save($batch); 

Is it possible to save entities in such a way that it generates a single insert, not multiple ones?

I have also tried the
Code:
insertBatch()
function of the query builder class but it doesn't work.

grettings
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.