Skip to content

Commit

Permalink
filter nulls resulting in "spl_object_hash() expects parameter 1 to b…
Browse files Browse the repository at this point in the history
…e object, null given vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php..."
  • Loading branch information
bendavies committed Jan 21, 2019
1 parent 0a2a1ab commit 10fb2dc
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/AssociationHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 10fb2dc

Please sign in to comment.