Is it possible to compare the state of an entity object between the current "dirty" version (an object for which some of its properties have been changed have not yet been saved) and the "original" version (data still in the database).
My assumption was that I could have a “dirty” object, then pull out a new one from the database and compare the two. For instance:
$entity = $em->getRepository('MyContentBundle:DynamicContent')->find($id); $editForm = $this->createContentForm($entity); $editForm->bind($request); if ($editForm->isValid()) { $db_entity = $em->getRepository('MyContentBundle:DynamicContent')->find($id); // compare $entity to $db_entity $em->persist($entity); $em->flush(); return $this->redirect($this->generateUrl('content_edit', array('id' => $id))); }
But, in my experience, $ entity and $ db_entity are always the same object (and have the same data as $ entity, after the $ request bind form). Is there a way to get a new version of $ entity along with a dirty version for comparison? The solutions I saw all pulled out the right data before the form was bound, but I would rather not have this limitation.
Update: To clarify, I am looking for not only changes in the properties of objects, but also collections of objects associated with them.
source share