gpt4 book ai didi

doctrine-orm - 如何在 preUpdate 事件监听器中更改字段的值?

转载 作者:行者123 更新时间:2023-12-03 21:07:34 31 4
gpt4 key购买 nike

文档说:

Changes to fields of the passed entities are not recognized by the flush operation anymore, use the computed change-set passed to the event to modify primitive field values.



但它也说:

getEntityChangeSet() to get a copy of the changeset array. Changes to this returned array do not affect updating.



这是否意味着我不能在 preUpdate 事件监听器中更改实体的字段?如果没有,我将如何完成此更新?

最佳答案

显然,您需要自己重新计算变更集才能使更改生效:

$em = $args->getEntityManager();
$uow = $em->getUnitOfWork();
$meta = $em->getClassMetadata(get_class($entity));
$uow->recomputeSingleEntityChangeSet($meta, $entity);

关于doctrine-orm - 如何在 preUpdate 事件监听器中更改字段的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8930062/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com