title: What is the most optimised persist/flush strategy when several objects must be flushed twice?
body: <p>Let be an Entity: <strong>Article</strong>, with one attribute: <strong>title</strong>. We need to insert into database, through Doctrine ORM, a series of <strong><em>titles</em></strong> and <strong><em>translated titles</em></strong>. </p>
  
  <p>PS: The translated titles will be propagated by the Translatable extension into a second table. We don't need to know more about this extension. We only need to know that an object has to be flushed twice (or at two separate moments) to be inserted correctly in the database.</p>
  
  <p>So, we want to tell doctrine to insert into database N titles and their translations:</p>
  
  <pre><code>$this-&gt;createAndPersistArticle("1-some title in english",  "1-un titre en français")
  $this-&gt;createAndPersistArticle("2-another funny title",    "2-un drôle de titre")
  ...
  $this-&gt;createAndPersistArticle("N-last but not least",     "N-le dernier mais pas des moindres")
  //$this-&gt;getManager()-&gt;flush();
  </code></pre>
  
  <p>with this function:</p>
  
  <pre><code>private function createAndPersistArticle($title, $translatedTitle) {
      $anArticle = new Article();
      $anArticle-&gt;setTitle($title);
      $this-&gt;getManager()-&gt;persist($anArticle);
      $this-&gt;getManager()-&gt;flush();
  
      $anArticle-&gt;setTranslatableLocale('fr');
      $anArticle-&gt;setTitle($translatedTitle);
      $this-&gt;getManager()-&gt;persist($anArticle);
      $this-&gt;getManager()-&gt;flush(); // flush that can be avoided
  }
  </code></pre>
  
  <p>With this code, we <strong>persist 2*N times</strong> and <strong>flush 2*N times</strong>.</p>
  
  <p>If we delete the "flush that can be avoided" and uncomment the flush written after the several calls of the function, we will <strong>persist 2*N times</strong> and <strong>flush N+1 times</strong>, that is an improvement. (It will work because two <em>different</em> persisted objects don't overlap)</p>
  
  <p>I am wondering if there is more optimised way of telling doctrine what to do, for instance <strong>persisting 2*N times</strong> and <strong>flushing 2 times</strong> (one time for all titles and one time for all translated titles). What are your thoughts about this ?</p>