title: Doctrine setting entity id at a later time
body: <p>I have an application in which I would like to edit already-existing entities, but all changes should only be made once the user explicitly clicks on "Save". So while he is editing nothing happens to the original.</p>
  
  <p>Usually, that wouldn't be any problem, but since I'm saving changes over Ajax and not Symfony, I need to have that work-around.</p>
  
  <p>It's working perfectly fine except for the part where it's supposed to write the id of the original entity into the edited one (the original gets removed when saving the changes).</p>
  
  <p>At first I thought I'd copy all of the fields from the edited entity over into the original, but it's likely that, once fields are added, nobody will tell the application to also copy those fields over.</p>
  
  <p>Here's the relevant code:</p>
  
  <pre><code>$editedEntity-&gt;setId($originalEntity-&gt;getId());
  
  $em = $this-&gt;getDoctrine()-&gt;getManager();
  $em-&gt;remove($originalEntity);
  $em-&gt;flush();
  </code></pre>
  
  <p>Tl;dr</p>
  
  <p>How can I copy the id of an entity into a different one?</p>