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