开发者

Doctrine2: Native SQL alias in SELECT

$rsm = new ResultSetMapping;
$rsm->addEntityResult('Default_Model_School', 's');
$rsm->addMetaResult('s', 'distance', 'distance'); // no
$rsm->addFieldResult('s', 'id', 'id');
$rsm->addFieldResult('s', 'establishment_name', 'establishment_name');

$query = $this->_em->createNativeQuery(
                'SELECT *, a*b AS distance
                 FROM schools',
          开发者_JAVA技巧       $rsm);

I am trying to get distance out from the query.

I tried the following, which works but breaks my other queries...

$rsm->addMetaResult('s', 'distance', 'distance');

and added the column to my entity...

/**
* @var string $distance
* @Column(type="string")
*/
private $distance;

This does not seem right as the column does not exist.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜