我正在使用教义的事件侦听器类来实现数据库事件的日志记录。我正在使用 postUpdate 事件。我的 mongoDB 文档中有一个嵌入式文档。在 postUpdate 事件中,当我调用该$uow->getDocumentChangeSet($entity)
方法时,我只获取更改集对象中的更改值。例如
[0]=>
object(Tyre24\ProductBundle\Document\Translations)#1178 (1) {
["translations":protected]=>
object(Doctrine\ODM\MongoDB\PersistentCollection)#1216 (10) {
["snapshot":"Doctrine\ODM\MongoDB\PersistentCollection":private]=>
array(0) {
}
["coll":"Doctrine\ODM\MongoDB\PersistentCollection":private]=>
object(Doctrine\Common\Collections\ArrayCollection)#1217 (1) {
["_elements":"Doctrine\Common\Collections\ArrayCollection":private]=>
array(1) {
[0]=>
object(Tyre24\ProductBundle\Document\Translation)#1227 (3) {
["key":protected]=>
string(11) "testkey_new"
["language":protected]=>
string(5) "xx_XX"
["value":protected]=>
string(9) "testvalue"
}
}
}
}
}
[1]=>
object(Tyre24\ProductBundle\Document\Translations)#1178 (1) {
["translations":protected]=>
object(Doctrine\ODM\MongoDB\PersistentCollection)#1216 (10) {
["snapshot":"Doctrine\ODM\MongoDB\PersistentCollection":private]=>
array(0) {
}
["coll":"Doctrine\ODM\MongoDB\PersistentCollection":private]=>
object(Doctrine\Common\Collections\ArrayCollection)#1217 (1) {
["_elements":"Doctrine\Common\Collections\ArrayCollection":private]=>
array(1) {
[0]=>
object(Tyre24\ProductBundle\Document\Translation)#1227 (3) {
["key":protected]=>
string(11) "testkey_new"
["language":protected]=>
string(5) "xx_XX"
["value":protected]=>
string(9) "testvalue"
}
}
}
}
}
}
这里更改集数组的第一个元素应该反映嵌入文档的旧状态,但它始终在两个数组索引中显示相同的(新)文档。对于没有嵌入文档的文档,它可以正常工作。任何想法?