diff --git a/src/Translation/Handlers/TranslatableEntityHandler.php b/src/Translation/Handlers/TranslatableEntityHandler.php index 8ac03db..877ffa8 100644 --- a/src/Translation/Handlers/TranslatableEntityHandler.php +++ b/src/Translation/Handlers/TranslatableEntityHandler.php @@ -71,8 +71,6 @@ public function translate(TranslationArgs $args) $clone->setLocale($args->getTargetLocale()); - $this->em->persist($clone); - return $clone; } diff --git a/tests/Fixtures/AppTestBundle/Entity/Translatable/TranslatableManyToManyBidirectionalParent.php b/tests/Fixtures/AppTestBundle/Entity/Translatable/TranslatableManyToManyBidirectionalParent.php index 076f367..9d1dbdb 100644 --- a/tests/Fixtures/AppTestBundle/Entity/Translatable/TranslatableManyToManyBidirectionalParent.php +++ b/tests/Fixtures/AppTestBundle/Entity/Translatable/TranslatableManyToManyBidirectionalParent.php @@ -29,6 +29,7 @@ class TranslatableManyToManyBidirectionalParent implements TranslatableInterface * * @ORM\ManyToMany( * targetEntity="AppTestBundle\Entity\Translatable\TranslatableManyToManyBidirectionalChild", + * cascade={"persist"}, * mappedBy="simpleParents" * ) */ @@ -39,6 +40,7 @@ class TranslatableManyToManyBidirectionalParent implements TranslatableInterface * * @ORM\ManyToMany( * targetEntity="AppTestBundle\Entity\Translatable\TranslatableManyToManyBidirectionalChild", + * cascade={"persist"}, * mappedBy="emptyParents" * ) * @ORM\JoinTable(name="empty_translatablemanytomanybidirectionalchild_translatablemanytomanybidirectionalparent") diff --git a/tests/ScalarTranslationTest.php b/tests/ScalarTranslationTest.php index 6780f79..1c782e3 100644 --- a/tests/ScalarTranslationTest.php +++ b/tests/ScalarTranslationTest.php @@ -17,6 +17,7 @@ public function it_can_translate_scalar_value() { $entity = $this->createEntity(); $translation = $this->translator->translate($entity, 'fr'); + $this->em->persist($translation); $this->em->flush(); $this->assertAttributeContains('Test title', 'title', $translation); $this->assertIsTranslation($entity, $translation); @@ -48,6 +49,7 @@ public function it_can_empty_scalar_value_on_translate() $entity = $this->createEntity(); $translation = $this->translator->translate($entity, 'fr'); + $this->em->persist($translation); $this->em->flush(); $this->assertAttributeEmpty('empty', $translation); $this->assertIsTranslation($entity, $translation); diff --git a/tests/TranslatableManyToOneEntityTranslationTest.php b/tests/TranslatableManyToOneEntityTranslationTest.php index 10295dc..18e6ddb 100644 --- a/tests/TranslatableManyToOneEntityTranslationTest.php +++ b/tests/TranslatableManyToOneEntityTranslationTest.php @@ -27,6 +27,7 @@ public function it_can_translate_simple_value() /** @var TranslatableManyToOne $translation */ $translation = $this->translator->translate($entity, self::TARGET_LOCALE); + $this->em->persist($translation); $this->em->flush(); $this->assertNotEquals($associatedEntity, $translation->getSimple()); $this->assertAttributeContains(self::TARGET_LOCALE, 'locale', $translation->getSimple()); @@ -41,6 +42,7 @@ public function it_must_associate_existing_translation() $this->em->persist($associatedEntity); $translatedAssociatedEntity = $this->translator->translate($associatedEntity, self::TARGET_LOCALE); + $this->em->persist($translatedAssociatedEntity); $entity = (new TranslatableManyToOne()) @@ -52,6 +54,7 @@ public function it_must_associate_existing_translation() /** @var TranslatableManyToOne $translation */ $translation = $this->translator->translate($entity, self::TARGET_LOCALE); + $this->em->persist($translation); $this->em->flush(); $this->assertNotEquals($associatedEntity, $translation->getSimple()); $this->assertEquals($translatedAssociatedEntity, $translation->getSimple()); diff --git a/tests/TranslatableOneToOneUnidirectionalTest.php b/tests/TranslatableOneToOneUnidirectionalTest.php index fd8c0ed..e6e3300 100644 --- a/tests/TranslatableOneToOneUnidirectionalTest.php +++ b/tests/TranslatableOneToOneUnidirectionalTest.php @@ -27,6 +27,7 @@ public function it_can_translate_simple_value() /** @var TranslatableOneToOneUnidirectional $translation */ $translation = $this->translator->translate($entity, self::TARGET_LOCALE); + $this->em->persist($translation); $this->em->flush(); $this->assertNotEquals($associatedEntity, $translation->getSimple()); $this->assertAttributeContains(self::TARGET_LOCALE, 'locale', $translation->getSimple());