Skip to content

Commit

Permalink
fix: eager loading can fail (#115)
Browse files Browse the repository at this point in the history
* fix: eager loading can fail

* Remove phpstan ignore annotation

---------

Co-authored-by: IanM <[email protected]>
  • Loading branch information
SychO9 and imorland authored Dec 12, 2023
1 parent ecb6b5c commit 89abb43
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/LoadActorVoteRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ public static function sumRelation($controller, $data): void
return $post instanceof Post;
});
} elseif ($data instanceof Collection) {
$loadable = $data->map(function ($model) {
$loadable = (new Post())->newCollection($data->map(function ($model) {
return $model instanceof Discussion ? ($model->mostRelevantPost ?? $model->firstPost) : $model;
});
}));
} elseif ($data instanceof Post) {
$loadable = $data->newCollection([$data]);
}

if ($loadable) {
/** @phpstan-ignore-next-line */
$loadable->loadSum('actualvotes', 'value');
}
}
Expand Down

0 comments on commit 89abb43

Please sign in to comment.