0

我有以下命令:

 $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,它工作得很好。知道为什么吗?

4

1 回答 1

1

你有没有忘记使用:

$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();
于 2013-10-22T05:42:27.773 回答