Symfony 4,使用EntityManager的nativeQuery方法的空结果

时间:2019-03-09 18:51:26

标签: mysql symfony4

我不明白为什么在Symfony中查询我的sql DB时为什么会得到一个空集。这是代码:

class LastEventsController extends AbstractController
{
public function index()
{
    $rsm = new ResultSetMapping();

    $entityManager = $this->getDoctrine()->getManager();
    $rsm = new ResultSetMappingBuilder($entityManager,ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT);


    $rsm->addRootEntityFromClassMetadata('App\Entity\NodeEvent', 'a');
    $rsm->addRootEntityFromClassMetadata('App\Entity\RockProtection', 'b');
    $query = $entityManager->createNativeQuery('select a.*, b.etagEad, b.code from nodeEvent a, rockProtection b where a.logger_id = b.logger_id', $rsm);
    $data = $query->getResult(); 

    return $this->render('last_events/index.html.twig', [
        'data' => $data,
    ]);
}
}

直接在mySql数据库中查询会产生3行,或者如果我尝试使用

$data=$entityManager->getConnection()->query('select a.*, b.etagEad, b.code from nodeEvent a, rockProtection b where a.logger_id = b.logger_id')->fetch();

有效

0 个答案:

没有答案