【发布时间】:2014-06-08 21:06:07
【问题描述】:
使用学说 2 在 zend 框架 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 的数据,我得到了旧值。
当我检查数据库时,新值就在那里。所以应该有一个技巧来重新组织我可能丢失的加载实体。
如何在 Persist 和 Flush 之后更新工作实体,以通过 $this->getEntityManager->getRepository() 获取新值而不是打开新连接?
【问题讨论】:
-
$entityManager->clear();
标签: php unit-testing symfony doctrine-orm