使用原则 2 开发 zend 框架 2。
在单元测试时,我使用“测试数据库”来添加、编辑和删除值。
问题是我添加了一个新实体,好吧。添加新实体后,女巫工作完美,我尝试更新实体。
//set all values
$this->getEntityManager->persist($dataEntity);
$this->getEntityManager->flush()
Run Code Online (Sandbox Code Playgroud)
当我尝试使用以下方法检索更新的数据时:
$produtoAcessorioCompareEntity = $this->getEntityManager()->getRepository('Administrador\Entity\ProdutoAcessorio')->findOneBy(array(
'idProdutoAcessorio' => $produtoAcessorioEntity->getIdProdutoAcessorio()
));
Run Code Online (Sandbox Code Playgroud)
但这缓存了 ADD 方法中的旧数据,并且没有更新新实体 $produtoAcessorioCompareEntity 的数据,我得到了旧值。
当我检查数据库时,新值就在那里。因此,应该有一个技巧来重新组织我可能缺少的已加载实体。
如何在持久和刷新后更新工作实体,以通过 $this->getEntityManager->getRepository() 获取新值,而不是打开新连接?