Doctrine2和Iterate时PostLoad事件的危险

时间:2015-08-18 23:25:02

标签: php doctrine-orm

在Doctrine2关于事件的文档中说:

Note that, when using Doctrine\ORM\AbstractQuery#iterate(), postLoad events will be executed immediately after objects are being hydrated, and therefore associations are not guaranteed to be initialized. It is not safe to combine usage of Doctrine\ORM\AbstractQuery#iterate() and postLoad event handlers.

为什么不安全?

迭代基本上是在迭代器的基础上对行进行水合,所以我没有区别。

AbstractQuery:

迭代中的

:   $this->_em->newHydrator($this->_hydrationMode)->iterate($stmt, $rsm, $this->_hints);

执行中的

$this->_em->newHydrator($this->_hydrationMode)->hydrateAll($stmt, $rsm, $this->_hints);

hydrateAllData调用hydrateRowData但生成快照:

    while ($row = $this->_stmt->fetch(PDO::FETCH_ASSOC)) {
        $this->hydrateRowData($row, $result);
    }

    // Take snapshots from all newly initialized collections
    foreach ($this->initializedCollections as $coll) {
        $coll->takeSnapshot();
    }

vs简单的hydrateRow。

关于那些快照吗?

0 个答案:

没有答案