我在启用 PostGIS 的 Postgre 数据库上使用 Symfony 和 Doctrine2。我有两张桌子 - 具有以下结构的财产和社区:
class Property {
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string")
*/
protected $address;
/**
* @var Point $geom
* @ORM\Column(type="Point", nullable=true)
*/
protected $geom;
}
class Neighborhood {
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $gid;
/**
* @ORM\Column(type="string")
*/
protected $name;
/**
* @ORM\Column(type="string")
*/
protected $description;
/**
* @var Polygon $geom
*
* @ORM\Column(type="Polygon", nullable=true)
*/
protected $geom;
}
在 pgAdminIII 中,我可以编写以下运行良好的查询:
SELECT address, neighborhood.name
FROM property
JOIN neighborhood
ON ST_Contains(neighborhood.geom, property.geom)
我怎样才能用 DQL 写这个?我了解连接的基础知识并为 Doctrine2 映射添加注释,但我不确定如何进行连接,因为这两个字段不相等。我需要使用 ST_Contains 函数来创建连接。我正在使用 djlambert / dictionary2-spatial 包进行空间数据类型和映射。我能够单独查询每个表并在每个表上创建了地图,但不确定如何选择给定社区中的所有属性。