From 10fb2dcba02bd4335404a5d12ada066bf9236986 Mon Sep 17 00:00:00 2001 From: Ben Davies Date: Mon, 21 Jan 2019 13:25:15 +0000 Subject: [PATCH] filter nulls resulting in "spl_object_hash() expects parameter 1 to be object, null given vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php..." --- src/AssociationHydrator.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/AssociationHydrator.php b/src/AssociationHydrator.php index 9794dda..b765e45 100644 --- a/src/AssociationHydrator.php +++ b/src/AssociationHydrator.php @@ -45,13 +45,12 @@ public function hydrateAssociations($subjects, iterable $associationsPaths): voi */ public function hydrateAssociation($subjects, string $associationPath): void { - if (null === $subjects || [] === $subjects) { + if ([] === $subjects = $this->normalizeSubject($subjects)) { return; } $initialAssociations = explode('.', $associationPath); $finalAssociation = array_pop($initialAssociations); - $subjects = $this->normalizeSubject($subjects); $classMetadata = $this->classMetadata; foreach ($initialAssociations as $initialAssociation) { @@ -90,13 +89,13 @@ public function hydrateAssociation($subjects, string $associationPath): void private function normalizeSubject($subject): array { if ($subject instanceof Collection) { - return $subject->toArray(); + $subject = $subject->toArray(); } if (!is_array($subject)) { - return [$subject]; + $subject = [$subject]; } - return $subject; + return \array_filter($subject); } }