php - persist() and flush() inside loop - Doctrine -


i want know how many times ff: codes make roundway trip database.

foreach ($recipients $recipient) {     $received_email = new receivedemail();     $received_email->setrecipient($recipient);     $received_email->setemail($email);      $entitymanager->persist($received_email);     $entitymanager->flush();  } 

$recipients array of user objects one-to-many relationship receivedemail

$email object one-to-many relationship receivedemail.

if instance $recipients has 5 entities, loop generates total of 5 trips database? or one?

is above example optimized way insert new receivedemail records?

thanks

there generated 1 insert statement each persist.

what more, can display yours sql statements debug, configure doctrine logging: https://stackoverflow.com/a/4585421/1815881

in case:

$entitymanager->getconfiguration()->                 setsqllogger(new \doctrine\dbal\logging\echosqllogger()); 

for many inserts should consider batch prcessing:

hope have revealed problem.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -