Skip to content

Commit

Permalink
Improve
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed May 25, 2024
1 parent cd572eb commit 022e521
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/ActiveQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use function array_combine;
use function array_flip;
use function array_intersect_key;
use function array_key_first;
use function array_map;
use function array_merge;
use function array_values;
Expand All @@ -35,6 +36,7 @@
use function in_array;
use function is_array;
use function is_int;
use function is_scalar;
use function is_string;
use function preg_match;
use function reset;
Expand Down Expand Up @@ -313,7 +315,10 @@ private function removeDuplicatedModels(array $models): array
$hash = array_column($models, reset($pks));
} else {
$flippedPks = array_flip($pks);
$hash = array_map(static fn ($model) => serialize(array_intersect_key($model, $flippedPks)), $models);
$hash = array_map(
static fn ($model): string => serialize(array_intersect_key($model, $flippedPks)),
$models
);
}
} else {
$pks = $model->getPrimaryKey(true);
Expand All @@ -329,9 +334,10 @@ private function removeDuplicatedModels(array $models): array
}

if (count($pks) === 1) {
$hash = array_map(static fn ($model): mixed => $model->getPrimaryKey(), $models);
$key = array_key_first($pks);
$hash = array_map(static fn ($model): string => (string) $model->getAttribute($key), $models);
} else {
$hash = array_map(static fn ($model): mixed => serialize($model->getPrimaryKey(true)), $models);
$hash = array_map(static fn ($model): string => serialize($model->getPrimaryKey(true)), $models);
}
}

Expand Down

0 comments on commit 022e521

Please sign in to comment.