From 3539c02b36703d0d87e84ce83cf169d959955485 Mon Sep 17 00:00:00 2001 From: Sullivan SENECHAL Date: Tue, 4 Oct 2016 16:06:47 +0200 Subject: [PATCH] Fallback to native entity if no revision found for properties If an audited entity has relational properties, the reader will try to find them as the same version, or previous. But if the targeted class does not has any revision at all, this produces a NoRevisionFound exception. This should be catched and should fallback to a classic doctrine find query. --- src/SimpleThings/EntityAudit/AuditReader.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/SimpleThings/EntityAudit/AuditReader.php b/src/SimpleThings/EntityAudit/AuditReader.php index 6a53378c..88b5ee9a 100644 --- a/src/SimpleThings/EntityAudit/AuditReader.php +++ b/src/SimpleThings/EntityAudit/AuditReader.php @@ -443,6 +443,9 @@ private function createEntity($className, array $columnMap, array $data, $revisi $value = $this->find($targetClass->name, $pk, $revision, array('threatDeletionsAsExceptions' => true)); } catch (DeletedException $e) { $value = null; + } catch (NoRevisionFoundException $e) { + // The entity does not have any revision yet. So let's get the actual state of it. + $value = $this->em->find($targetClass->name, $pk); } $class->reflFields[$field]->setValue($entity, $value);