From 9d70b61730a255c24db65416570b74bb69f21ce6 Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Tue, 12 Dec 2023 15:22:27 +0100 Subject: [PATCH] fix: avoid edge cases with eager loading (#116) --- src/LoadActorVoteRelationship.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/LoadActorVoteRelationship.php b/src/LoadActorVoteRelationship.php index 2543223..3ca41b4 100644 --- a/src/LoadActorVoteRelationship.php +++ b/src/LoadActorVoteRelationship.php @@ -40,12 +40,12 @@ public static function sumRelation($controller, $data): void } elseif ($data instanceof Collection) { $loadable = (new Post())->newCollection($data->map(function ($model) { return $model instanceof Discussion ? ($model->mostRelevantPost ?? $model->firstPost) : $model; - })); + })->filter()); } elseif ($data instanceof Post) { $loadable = $data->newCollection([$data]); } - if ($loadable) { + if ($loadable && $loadable instanceof Collection) { $loadable->loadSum('actualvotes', 'value'); } }