开发者

Doctrine2: Native SQL alias in SELECT

开发者 https://www.devze.com 2023-03-19 20:51 出处:网络
$rsm = new ResultSetMapping; $rsm->addEntityResult(\'Default_Model_School\', \'s\'); $rsm->addMetaResult(\'s\', \'distance\', \'distance\'); // no
$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

精彩评论

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

关注公众号