我有以下命令:
$rsm = new ResultSetMapping();
$query = $this->em->createNativeQuery('SELECT userid FROM prospective_shop WHERE LENGTH(bio) = 0 ORDER BY RAND()', $rsm);
//$query->setMaxResults(10);
$prospectiveShops = $query->getResult();
这里它给了我一个空数组。我复制粘贴SQL,它工作得非常好。知道为什么吗?
答案 0 :(得分:0)
你有没有忘记使用:
$rsm->addFieldResult(...);
将查询结果映射到学说对象?
编辑:
尝试这种方式:
$rsm = new ResultSetMapping();
$rsm->addEntityResult('my\bundle\Entity\ProsprectiveShop', 's');
$rsm->addFieldResult('s','userid','userid');
$query = $this->em->createNativeQuery('SELECT userid FROM prospective_shop s WHERE LENGTH(bio) = 0 ORDER BY RAND()', $rsm);
$prospectiveShops = $query->getResult();