From ebd00b76950094cfafde9c945aefb79c2e2f6820 Mon Sep 17 00:00:00 2001 From: Martin Lojda Date: Fri, 25 Oct 2024 13:26:56 +0200 Subject: [PATCH 1/2] Embeddable as part of composite primary key --- src/Mapper/Dbal/Conventions/Conventions.php | 8 ++++++++ src/Repository/IdentityMap.php | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Mapper/Dbal/Conventions/Conventions.php b/src/Mapper/Dbal/Conventions/Conventions.php index c7f30a95..6855aa3a 100644 --- a/src/Mapper/Dbal/Conventions/Conventions.php +++ b/src/Mapper/Dbal/Conventions/Conventions.php @@ -389,6 +389,10 @@ protected function getDefaultMappings(): array $subMetadata = $property->args[EmbeddableContainer::class]['metadata']; assert($subMetadata instanceof EntityMetadata); + if ($property->isPrimary) { + unset($entityPrimaryKey[array_search($property->name, $entityPrimaryKey)]); + } + $baseTokens = $tokens; $baseTokens[] = $property->name; @@ -405,6 +409,10 @@ protected function getDefaultMappings(): array }, $propertyTokens), ); + if ($property->isPrimary) { + $entityPrimaryKey[] = $propertyKey; + } + $mappings[self::TO_ENTITY][$storageKey] = [$propertyKey]; $mappings[self::TO_STORAGE][$propertyKey] = [$storageKey]; $mappings[self::TO_STORAGE_FLATTENING][$propertyKey] = $propertyTokens; diff --git a/src/Repository/IdentityMap.php b/src/Repository/IdentityMap.php index 65fe5a1b..e421fdad 100644 --- a/src/Repository/IdentityMap.php +++ b/src/Repository/IdentityMap.php @@ -199,7 +199,7 @@ protected function getIdHash($id): string function ($id): string { return $id instanceof DateTimeImmutable ? $id->format('c.u') - : (string) $id; + : (is_array($id) ? $this->getIdHash($id) : (string) $id); }, $id ) From 99c625c757ed79999471167a3602a04690d7ac6b Mon Sep 17 00:00:00 2001 From: Martin Lojda Date: Fri, 25 Oct 2024 13:34:15 +0200 Subject: [PATCH 2/2] fixed property lookup fo phpstan --- src/Mapper/Dbal/Conventions/Conventions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mapper/Dbal/Conventions/Conventions.php b/src/Mapper/Dbal/Conventions/Conventions.php index 6855aa3a..d4514a51 100644 --- a/src/Mapper/Dbal/Conventions/Conventions.php +++ b/src/Mapper/Dbal/Conventions/Conventions.php @@ -390,7 +390,7 @@ protected function getDefaultMappings(): array assert($subMetadata instanceof EntityMetadata); if ($property->isPrimary) { - unset($entityPrimaryKey[array_search($property->name, $entityPrimaryKey)]); + unset($entityPrimaryKey[array_search($property->name, $entityPrimaryKey, true)]); } $baseTokens = $tokens;