我试图在调用getIdentityMap方法后找出确切返回的内容 UnitOfWork对象。
我实际上可以看到的是一组实体,它们可能对应于我被实体管理器刷新的最新实体。
我在postFlush事件后访问\ Doctrine \ ORM \ Event \ PostFlushEventArgs中的getUnitOfWork。
答案 0 :(得分:0)
/**
* The identity map that holds references to all managed entities that have
* an identity. The entities are grouped by their class name.
* Since all classes in a hierarchy must share the same identifier set,
* we always take the root class name of the hierarchy.
*
* @var array
*/
private $identityMap = array();
ORM中通常使用design pattern来确保每个请求只加载一个实例。
因此,第一次查询实体管理器时,它将从数据库加载,然后使用唯一键(spl_object_id()
)将指向此实体的指针添加到标识映射数组中。在第二次调用时,返回相同实例。