我可以在Doctrine2的onFlush eventListerner中访问更新的文档。 我想要完整的旧文档将其存储在其他地方作为旧状态。
public function onFlush(OnFlushEventArgs $eventArgs)
{
$dm = $eventArgs->getDocumentManager();
$uow = $dm->getUnitOfWork();
foreach ($uow->getScheduledDocumentUpdates() as $document) {
// $document is updated document
// $changeSet contains only new and old values
$changeSet = $uow->getDocumentChangeSet($document);
// I want the whole old document object as $oldDocument
}
}
如何访问旧文档而不仅仅是更改集?
最佳答案
只需使用preUpdate 事件。示例:
public function preUpdate(PreUpdateEventArgs $event)
{
$entity = $event->getEntity(); // the whole entity
$changeSet = $event->getEntityChangeSet(); // only changed properties
// check if password has been changed
if ($event->hasChangedField('password')) {
// do stuff
}
/* ... */
}
关于mongodb - Doctrine EventListener onFlush 访问旧文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40573882/