title: Doctrine2 Entites - Is it possible to compare a "dirty" object to one from the database
body: <p>Is it possible to compare the state of an entity object between the current "dirty" version (an object that has some of its properties changed, not yet persisted) and the "original" version (the data still in the database).</p>
  
  <p>My assumption was that I could have a "dirty" object, then pull a fresh one from the DB and compare the two. For instance:</p>
  
  <pre><code>$entity = $em-&gt;getRepository('MyContentBundle:DynamicContent')-&gt;find($id);
  
  $editForm = $this-&gt;createContentForm($entity);
  $editForm-&gt;bind($request);
  
  if ($editForm-&gt;isValid()) {
      $db_entity = $em-&gt;getRepository('MyContentBundle:DynamicContent')-&gt;find($id);
  
      // compare $entity to $db_entity
  
      $em-&gt;persist($entity);
      $em-&gt;flush();
  
      return $this-&gt;redirect($this-&gt;generateUrl('content_edit', array('id' =&gt; $id)));
  }
  </code></pre>
  
  <p>But in my experience, $entity and $db_entity are always the same object (and have the same data as $entity, after the form $request bind). Is there a way to get a fresh version of the $entity alongside the "dirty" version for comparison's sake? The solutions I've seen all pull the needed data before the form bind happens, but I'd rather not have that limitation.</p>
  
  <p><strong>Update:</strong> To clarify, I'm looking not only for changes to the entities' properties but also its related collections of entities.</p>