I want to know how many times the ff: codes will make a roundway trip to the database.
foreach ($recipients as $recipient) {
$received_email = new ReceivedEmail();
$received_email->setRecipient($recipient);
$received_email->setEmail($email);
$entityManager->persist($received_email);
$entityManager->flush();
}
$recipients
is an array of User objects with One-to-Many relationship with ReceivedEmail
$email
is an object with One-to-Many relationship with ReceivedEmail.
If for instance $recipients
has five entities, does the loop generates a total of five trips to database? Or only one?
Is the above example the most optimized way to insert new ReceivedEmail records?
Thanks