diff --git a/CHANGELOG.md b/CHANGELOG.md index b3021898e..7462009e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ You can find and compare releases at the [GitHub release page](https://github.co ## Unreleased +### Changed + +- Compare raw attributes only when ensuring uniqueness of paginated related models https://github.com/nuwave/lighthouse/pull/2540 + ## v6.36.1 ### Fixed diff --git a/src/Execution/ModelsLoader/PaginatedModelsLoader.php b/src/Execution/ModelsLoader/PaginatedModelsLoader.php index 476a8c620..3bbeadb08 100644 --- a/src/Execution/ModelsLoader/PaginatedModelsLoader.php +++ b/src/Execution/ModelsLoader/PaginatedModelsLoader.php @@ -12,6 +12,7 @@ use Nuwave\Lighthouse\Pagination\PaginationArgs; use Nuwave\Lighthouse\Pagination\ZeroPerPageLengthAwarePaginator; use Nuwave\Lighthouse\Support\Utils; +use function Safe\json_encode; class PaginatedModelsLoader implements ModelsLoader { @@ -84,7 +85,7 @@ protected function loadRelatedModels(EloquentCollection $parents): EloquentColle return $relatedModels->unique( // Compare all attributes because there might not be a unique primary key // or there could be differing pivot attributes. - static fn (Model $relatedModel): string => $relatedModel->toJson(), + static fn (Model $relatedModel): string => json_encode($relatedModel->getOriginal()), ); }