在zend框架2和理论2上一起工作。
在进行单元测试时,我使用“测试数据库”来添加,编辑和删除值。
问题是我添加了一个新实体,好的。添加新实体后,女巫可以完美工作,我尝试更新该实体。
//set all values
$this->getEntityManager->persist($dataEntity);
$this->getEntityManager->flush()
当我尝试使用以下方法检索更新的数据时:
$produtoAcessorioCompareEntity = $this->getEntityManager()->getRepository('Administrador\Entity\ProdutoAcessorio')->findOneBy(array(
'idProdutoAcessorio' => $produtoAcessorioEntity->getIdProdutoAcessorio()
));
但这从ADD方法缓存了旧数据,但没有更新新实体$ produtoAcessorioCompareEntity的数据,我得到了旧值。
当我检查数据库时,新值在那里。因此,应该有一个技巧来重组我可能会丢失的已加载实体。
如何在“持久和刷新”后更新工作实体,以通过$ this-> getEntityManager-> getRepository()获取新值,而不是打开一个新连接?
$ this-> getEntityManager()-> refresh($ entity);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句