我已经创建了事件侦听器
class ProcessPostLoadListener
{
public function postLoad(LifecycleEventArgs $args)
{
$em = $args->getEntityManager();
$entity = $args->getEntity();
if ($entity instanceof Process) {
.
.
.
}
}
}
当我使用getRepository(Process::class)->find($id)获取数据时,将调用postLoad方法,并且我可以修改数据。
但是当使用查询构建器获取数据时
$qb = $this->createQueryBuilder('p')
->select('PARTIAL p.{id,answersInRelatedQuestionnaires}')
->where('p.id = :processId')
->setParameter('processId', $processId);
未调用postLoad。我能做什么?是否有其他事件可供监听?
谢谢
发布于 2018-12-08 10:36:45
引用documentation教义
在将实体从数据库加载到当前EntityManager中或对其应用刷新操作后,实体会发生
PostLoad事件
这意味着只有在实体对象被消隐时才会调度PostLoad事件,而且只有在消隐模式被设置为HYDRATE_OBJECT时才会发生这种情况。由于您使用的是HYDRATION_ARRAY,因此会返回一个关联数组,并且没有实体对象会被合并,这就是PostLoad事件不会发生的原因。
https://stackoverflow.com/questions/53672283
复制相似问题