symfony2 doctrine mongodb - 如何检查文档中的字段是否已更新

时间:2016-04-22 03:11:22

标签: php mongodb symfony doctrine

doctrine mongodb的{​​{1}}中,有没有办法捕获偶数symfony2postUpdateonFlush以检查文档中的字段是否为更新?我的示例是文档preUpdate,其中包含字段Post。我有一个Id, name, description来跟踪Listener service更新时的事件。

Post

1 个答案:

答案 0 :(得分:1)

preUpdate期间,您可以查看文档的更改集:

public function preUpdate(PreUpdateEventArgs $e)
{
    $e->getDocumentChangeSet();
    $e->hasChangedField('description')
}

Changeset是关联元组,看起来像

[ 'description' => [ 'old value', 'new value' ] ]

有关更多可用方法,您可以查看PreUpdateEventArgs