Orm ';中的Doctrine2本机查询或错误;as';

Orm ';中的Doctrine2本机查询或错误;as';,orm,symfony,doctrine,doctrine-orm,Orm,Symfony,Doctrine,Doctrine Orm,我想使用本机查询使用'as'子句来设置类属性: public function findIntersects($id,$pontos){ $em = $this->getEntityManager(); $sql = "SELECT p.imovel,p.id,ST_Area(ST_Intersection(p.location,'POLYGON((".$pontos."))')) as area_int, ST_Area(p.location) as area from propr

我想使用本机查询使用'as'子句来设置类属性:

public function findIntersects($id,$pontos){

$em = $this->getEntityManager();

 $sql = "SELECT p.imovel,p.id,ST_Area(ST_Intersection(p.location,'POLYGON((".$pontos."))')) as area_int, ST_Area(p.location) as area from propriedades p where ST_Intersects(p.location,'POLYGON((".$pontos."))') and id !=:id";

$rsm = new ResultSetMapping;
$rsm->addEntityResult('Incra\PropriedadesBundle\Entity\Propriedades', 'o');
$rsm->addFieldResult('o', 'id', 'id');
$rsm->addFieldResult('o', 'imovel', 'imovel');
$rsm->addFieldResult('o', 'area_int', 'area_int');
$rsm->addFieldResult('o', 'area', 'area');

 $qns = $this->_em->createNativeQuery($sql, $rsm);
$qns->setParameter("id", $id);
$qns->setParameter("pontos", $pontos);


  return $qns->getResult();


}
我的类中有这个属性,但没有orm的注释

我得到一个错误:

注意:未定义的索引:中的area_int /var/www/incra/vendor/doctrine/lib/doctrine/ORM/Internal/Hydration/AbstractHydrator.php 第205行


我的类:

您没有将
区域\u int
标记为数据列(您的类中的第120行)。由于您已在字段结果(
$rsm->addFieldResult('o','area\u int','area\u int');
)中列出了
area\u int
),因此条令尝试将列映射到实体,但找不到它。尝试用

/**@ORM\Column(name="area_int", type="int")*/
private $area_int;
另外,为了安全性/性能/代码风格/等等,您直接在查询字符串中注入
$pontos
。这使您的代码受制于SQL注入。稍后,添加
$pontos
作为参数。这两种方法是多余的,因此您最好删除其中一种。我肯定会尝试使用参数方法,这样您的查询就会变成

SELECT p.imovel,p.id,ST_Area(ST_Intersection(p.location,'POLYGON((:pontos))')) as area_int, 
       ST_Area(p.location) as area from propriedades p 
where ST_Intersects(p.location,'POLYGON((:pontos))') and id !=:id

如果它不起作用,您可以删除
$qns->setParameter(“pontos”,$pontos),但是您应该执行尽可能多的健全性检查和验证,以防止SQL注入。

使用executeQuery来使用本机而不使用dql

但是'area_int'不是数据库表中的一列,是psql函数的返回,我不想将其设为列。我知道$pontos,但是这个值直接从数据库中获取并被验证