我需要根据某些实体的更改来创建历史记录,我想将所有更改保留在新表中。我正在尝试从EventListeners preUpdate执行它。但是,当我尝试进行刷新以保留新对象时,出现错误存储,这是我创建循环引用的原因。 是否可以从preUpdate(而不是当前实体)创建一个新的实体并允许其访问
class TestListener {
private $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public function preUpdate(LifecycleEventArgs $args)
{
$entity = $args->getObject();
/*if (!$entity instanceof Product) {
return;
}*/
$entityManager = $args->getObjectManager();
$histoRVSrep = $entityManager->getRepository('AppBundle:HistoRapportSterilisation');
$histo = new HistoRapportSterilisation();
foreach ($args->getEntityChangeSet() as $key => $value) {
$t = "set".ucfirst($key);
$histo->$t($value[0]);
};
$entityManager->persist($histo);
$entityManager->flush();
}
我做错了什么? 谢谢