首页 > 解决方案 > findBy() 返回 null 但 db 已满

问题描述

我必须在需要比较两个 id 的地方建立 db 表。在表一中,我有 $id,在其他表中,我有 $previousId。

第一个表 id 由查询生成器找到,第二个我需要通过我设置的存储库找到。

每次我 dump() 结果时,即使我的数据库中有多个字段具有 previousId 值,它也会返回 [] 。

我的代码:

 public function myMethod($previousId)
{
    $tableOne = $this->getTableOneRepository()
        ->createQueryBuilder('e')
        ->select('e')
        ->getQuery()
        ->getResult();

    $tableTwo = $this->getTableTwoRepository()->findBy(['previousId' => $previousId]);

     dump(tableTwo);die;  ----// returns [] even I if have table data

        if($tableOne->getId() == $tableTwo->getPreviousId){
            throw new \Exception('This message is already been archived.');
    }

}

标签: phpsymfonyclassdoctrinerepository

解决方案


推荐阅读