Sql 为order by it添加虚拟列,但不返回虚拟列

Sql 为order by it添加虚拟列,但不返回虚拟列,sql,postgresql,doctrine,postgis,dql,Sql,Postgresql,Doctrine,Postgis,Dql,我有一个具有点(postgis)属性的实体。我需要返回该实体的集合,该集合按用户坐标与实体点之间的距离排序 为此,我添加了一个聚合函数来计算该距离,并按顺序添加,但我不想返回它。我只需要返回和实体对象数组 如果没有order by,结果是: [ { "user": "/api/users/1", "id": 1, "gender": "MALE", "createdAt": "2019-04-05T11:03:03+02:00", "updateAt"

我有一个具有点(postgis)属性的实体。我需要返回该实体的集合,该集合按用户坐标与实体点之间的距离排序

为此,我添加了一个聚合函数来计算该距离,并按顺序添加,但我不想返回它。我只需要返回和实体对象数组

如果没有order by,结果是:

[
  {
    "user": "/api/users/1",
    "id": 1,
    "gender": "MALE",
    "createdAt": "2019-04-05T11:03:03+02:00",
    "updateAt": "2019-04-11T11:34:06+02:00",
    "birthdate": "1991-05-13T08:02:32+02:00",
    "deletedAt": null,
    "town": "Miami"
  },
  {
    "user": "/api/users/3",
    "id": 2,
    "gender": "MALE",
    "createdAt": "2019-04-05T13:59:30+02:00",
    "updateAt": "2019-04-11T10:57:40+02:00",
    "birthdate": "1999-04-05T11:48:46+02:00",
    "deletedAt": null,
    "town": "New York"
  },
  {
    "user": "/api/users/7",
    "id": 3,
    "gender": "MALE",
    "createdAt": "2019-04-11T11:11:03+02:00",
    "updateAt": "2019-04-11T11:11:03+02:00",
    "birthdate": "1991-05-13T08:02:32+02:00",
    "deletedAt": null,
    "town": "New York"
  }
]
当我为ORDER BY disntace添加下一个代码时(在用户坐标和点坐标之间计算)

我得到:

[
  {
    "0": {
        "user": "/api/users/1",
        "id": 1,
        "gender": "MALE",
        "createdAt": "2019-04-05T11:03:03+02:00",
        "updateAt": "2019-04-11T11:34:06+02:00",
        "birthdate": "1991-05-13T08:02:32+02:00",
        "deletedAt": null,
        "town": "Miami"
    },
    "distance": "106496.35623204"
  },
  {
    "0": {
        "user": "/api/users/7",
        "id": 3,
        "gender": "MALE",
        "createdAt": "2019-04-11T11:11:03+02:00",
        "updateAt": "2019-04-11T11:11:03+02:00",
        "birthdate": "1991-05-13T08:02:32+02:00",
        "deletedAt": null,
        "town": "New York"
    },
    "distance": "109073.2944295"
  },
  {
    "0": {
        "user": "/api/users/3",
        "id": 2,
        "gender": "MALE",
        "createdAt": "2019-04-05T13:59:30+02:00",
        "updateAt": "2019-04-11T10:57:40+02:00",
        "birthdate": "1999-04-05T11:48:46+02:00",
        "deletedAt": null,
        "town": "New York"
    },
    "distance": "285892.32591062"
  }
]
我需要让结果看起来像第一个json。可以按添加订单,但可以删除/隐藏距离属性?

使用隐藏关键字,以便从结果中省略计算字段:

->addSelect("ST_Distance(o.point, ST_Point(:longitude,:latitude)) AS HIDDEN distance")

->addSelect("ST_Distance(o.point, ST_Point(:longitude,:latitude)) AS HIDDEN distance")