Skip to content

Commit

Permalink
Merge pull request #4 from bendavies/fix-null-subjects
Browse files Browse the repository at this point in the history
filter nulls
  • Loading branch information
damonsson authored Apr 23, 2024
2 parents e7436ce + 10fb2dc commit c39d464
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 @@ -48,13 +48,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 @@ -93,13 +92,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 c39d464

Please sign in to comment.