Php 原则2将数据更新到数据库中,但不将数据更新到实体中

Php 原则2将数据更新到数据库中,但不将数据更新到实体中,php,unit-testing,symfony,doctrine-orm,Php,Unit Testing,Symfony,Doctrine Orm,正在使用条令2研究zend框架2 在进行单元测试时,我使用“测试数据库”从中添加、编辑和删除值 问题是我添加了一个新实体,好的。 在我添加新实体witch works perfecty之后,我尝试更新该实体 //set all values $this->getEntityManager->persist($dataEntity); $this->getEntityManager->flush() 当我尝试使用以下方法检索更新的数据时: $produtoAces

正在使用条令2研究zend框架2

在进行单元测试时,我使用“测试数据库”从中添加、编辑和删除值

问题是我添加了一个新实体,好的。 在我添加新实体witch works perfecty之后,我尝试更新该实体

//set all values
$this->getEntityManager->persist($dataEntity);
$this->getEntityManager->flush()
当我尝试使用以下方法检索更新的数据时:

    $produtoAcessorioCompareEntity = $this->getEntityManager()->getRepository('Administrador\Entity\ProdutoAcessorio')->findOneBy(array(
        'idProdutoAcessorio' => $produtoAcessorioEntity->getIdProdutoAcessorio()
    ));
但是这缓存了ADD方法中的旧数据,并没有更新新实体$produtacessoriocompareentity的数据,我得到了旧值

当我检查数据库时,新值就在那里。所以应该有一个技巧来重新组织加载的实体,这可能是我缺少的


如何在Persist和Flush之后更新工作实体,以通过$this->getEntityManager->getRepository()获取新值,而不是打开一个新连接?

好吧,您的代码似乎没有错,但是,您可以尝试使用
find()
方法:

$produtoAcessorioCompareEntity = $this->getEntityManager()
    ->find('Administrador\Entit\ProdutoAcessorio', $produtoAcessorioEntity->getIdProdutoAcessorio());

好的,您的代码似乎没有错,但是,您可以尝试使用
find()
方法:

$produtoAcessorioCompareEntity = $this->getEntityManager()
    ->find('Administrador\Entit\ProdutoAcessorio', $produtoAcessorioEntity->getIdProdutoAcessorio());

$this->getEntityManager()->刷新($entity)

$this->getEntityManager()->刷新($entity)

$entityManager->clear()$entityManager->clear();我也有同样的问题,这就成功了。谢谢我也有同样的问题,这就成功了。谢谢