diff --git a/src/EventSubscriber/TranslatableEventSubscriber.php b/src/EventSubscriber/TranslatableEventSubscriber.php index a55b68da..c37fd379 100644 --- a/src/EventSubscriber/TranslatableEventSubscriber.php +++ b/src/EventSubscriber/TranslatableEventSubscriber.php @@ -123,7 +123,7 @@ private function mapTranslation(ClassMetadataInfo $classMetadataInfo, ObjectMana /** @var ClassMetadataInfo $classMetadata */ $classMetadata = $objectManager->getClassMetadata($targetEntity); - $singleIdentifierFieldName = $classMetadata->getSingleIdentifierFieldName(); + $singleIdentifierColumnName = $classMetadata->getSingleIdentifierColumnName(); $classMetadataInfo->mapManyToOne([ 'fieldName' => 'translatable', @@ -132,7 +132,7 @@ private function mapTranslation(ClassMetadataInfo $classMetadataInfo, ObjectMana 'fetch' => $this->translationFetchMode, 'joinColumns' => [[ 'name' => 'translatable_id', - 'referencedColumnName' => $singleIdentifierFieldName, + 'referencedColumnName' => $singleIdentifierColumnName, 'onDelete' => 'CASCADE', ]], 'targetEntity' => $targetEntity, diff --git a/tests/Fixtures/Entity/TranslatableEmbeddableUuid.php b/tests/Fixtures/Entity/TranslatableEmbeddableUuid.php new file mode 100644 index 00000000..a6ce131e --- /dev/null +++ b/tests/Fixtures/Entity/TranslatableEmbeddableUuid.php @@ -0,0 +1,28 @@ +value = $value; + } + + public static function random(): self + { + return new self(Uuid::uuid4()->toString()); + } +} \ No newline at end of file diff --git a/tests/Fixtures/Entity/TranslatableEmbeddedIdentifierEntity.php b/tests/Fixtures/Entity/TranslatableEmbeddedIdentifierEntity.php new file mode 100644 index 00000000..20e2324f --- /dev/null +++ b/tests/Fixtures/Entity/TranslatableEmbeddedIdentifierEntity.php @@ -0,0 +1,38 @@ +uuid = TranslatableEmbeddableUuid::random(); + } + + /** + * @param mixed[] $arguments + * @return mixed + */ + public function __call(string $method, array $arguments) + { + return $this->proxyCurrentLocaleTranslation($method, $arguments); + } + + public function getUuid(): TranslatableEmbeddableUuid + { + return $this->uuid; + } +} diff --git a/tests/Fixtures/Entity/TranslatableEmbeddedIdentifierEntityTranslation.php b/tests/Fixtures/Entity/TranslatableEmbeddedIdentifierEntityTranslation.php new file mode 100644 index 00000000..8dc69a02 --- /dev/null +++ b/tests/Fixtures/Entity/TranslatableEmbeddedIdentifierEntityTranslation.php @@ -0,0 +1,43 @@ +uuid = TranslatableEmbeddableUuid::random(); + } + + public function getUuid(): TranslatableEmbeddableUuid + { + return $this->uuid; + } + + public function getTitle(): ?string + { + return $this->title; + } + + public function setTitle(string $title): void + { + $this->title = $title; + } +} diff --git a/tests/ORM/Translatable/TranslatableTest.php b/tests/ORM/Translatable/TranslatableTest.php index 90d0b7d9..e46b574a 100644 --- a/tests/ORM/Translatable/TranslatableTest.php +++ b/tests/ORM/Translatable/TranslatableTest.php @@ -12,6 +12,7 @@ use Knp\DoctrineBehaviors\Tests\Fixtures\Contract\Translatable\TranslatableEntityWithCustomInterface; use Knp\DoctrineBehaviors\Tests\Fixtures\Entity\TranslatableCustomIdentifierEntity; use Knp\DoctrineBehaviors\Tests\Fixtures\Entity\TranslatableCustomizedEntity; +use Knp\DoctrineBehaviors\Tests\Fixtures\Entity\TranslatableEmbeddedIdentifierEntity; use Knp\DoctrineBehaviors\Tests\Fixtures\Entity\TranslatableEntity; use Knp\DoctrineBehaviors\Tests\Fixtures\Entity\TranslatableEntityTranslation; use Knp\DoctrineBehaviors\Tests\Fixtures\Entity\Translation\TranslatableCustomizedEntityTranslation; @@ -76,6 +77,27 @@ public function testShouldPersistWithCustomIdentifier(): void $this->assertSame('awesome', $translatableEntity->translate('en')->getTitle()); } + public function testShouldPersistWithEmbeddedIdentifier(): void + { + $translatableEntity = new TranslatableEmbeddedIdentifierEntity(); + $translatableEntity->translate('en') + ->setTitle('awesome'); + $translatableEntity->mergeNewTranslations(); + + $this->entityManager->persist($translatableEntity); + $this->entityManager->flush(); + + $uuid = $translatableEntity->getUuid(); + $this->entityManager->clear(); + + /** @var TranslatableEntity $translatableEntity */ + $translatableEntity = $this->entityManager->getRepository(TranslatableEmbeddedIdentifierEntity::class)->find( + $uuid + ); + + $this->assertSame('awesome', $translatableEntity->translate('en')->getTitle()); + } + public function testShouldFallbackCountryLocaleToLanguageOnlyTranslation(): void { $translatableEntity = new TranslatableEntity();