我也遇到了这个问题,因为我希望每次运行时都有一些 id 相同,因为我想使用该UUID
策略在我的调试应用程序中引用它们。
我做了什么:
1)写了一个包装的命令hautelook:fixtures:load
:
protected function execute(InputInterface $input, OutputInterface $output)
{
$container = $this->getContainer();
$entityManager = $container->get('doctrine.orm.default_entity_manager');
$metadata = $entityManager->getClassMetaData(App::class);
$metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE);
$metadata->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator());
$application = new Application($kernel);
$application->setAutoExit(false);
$this->loadFixtures($application, $output);
}
$metadata
为您希望拥有自定义 id ( App::class
)的所有类执行-stuff。
protected function loadFixtures(Application $application, OutputInterface $output)
{
$loadFixturesInput = new ArrayInput(array(
'command' => 'hautelook:fixtures:load',
'--no-interaction' => 'true',
'--verbose' => '3'
));
$application->run($loadFixturesInput, $output);
}
2)我创建了一个模板来生成id
类似的学说。
id (template):
id (unique): '<uuid()>'
3)在我的自定义实体夹具中,现在我可以执行以下操作:
app_custom (extends id):
id: 'whatever-i-want'
title: 'My custom entity'
4)如果我不想使用自定义 ID,我只是不覆盖该id
字段:
app_another (extends id):
title: 'Just another app with an id I do not care about'
证明:
