sorry,i am not see the $category->mergeNewTranslations();
i follow the doc,create Category and CategoryTranslation entity
Category:
<?php
namespace App\Entity;
use App\Repository\CategoryRepository;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
/**
* @ORM\Entity(repositoryClass=CategoryRepository::class)
*/
class Category implements TranslatableInterface
{
use TranslatableTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
public function getId(): ?int
{
return $this->id;
}
}
CategoryTranslation:
namespace App\Entity;
use App\Repository\CategoryTranslationRepository;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface;
use Knp\DoctrineBehaviors\Model\Translatable\TranslationTrait;
/**
* @ORM\Entity(repositoryClass=CategoryTranslationRepository::class)
*/
class CategoryTranslation implements TranslationInterface
{
use TranslationTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
}
and on my CategoryFixtures:
<?php
namespace App\DataFixtures;
use App\Entity\Category;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
class CategoryFixtures extends Fixture
{
public function load(ObjectManager $manager)
{
$category = new Category();
$category->translate('en')->setName('Home');
$category->translate('zh_cn')->setName('首页');
$manager->persist($category);
$manager->flush();
}
}
when i load the fixture,only category table has on data.category_translation table has nothing
category table:
id int(11) AUTO_INCREMENT
category_translation :
id int(11) AUTO_INCREMENT
translatable_id int(11)
name varchar(255)
locale varchar(5)
sorry,i am not see the $category->mergeNewTranslations();
i follow the doc,create Category and CategoryTranslation entity
Category:
CategoryTranslation:
and on my CategoryFixtures:
when i load the fixture,only category table has on data.category_translation table has nothing
category table: id int(11) AUTO_INCREMENT
category_translation : id int(11) AUTO_INCREMENT translatable_id int(11) name varchar(255) locale varchar(5)