N
N
NookieNoo2021-11-16 14:48:37
PHP
NookieNoo, 2021-11-16 14:48:37

How to get 2 fields from the database by applying postgis-sql functions to them that refer to one column in the database?

I have some field in the database with geometry, which I want to pull out in 2 versions - in geojson, and as text, but the @ORM\Column annotation does not allow accessing the same field twice inside the Entity.
Those. the request should be something like this:

SELECT st_asgeojson(geometry) as geojson, st_astext(geometry) as geom_text,  ... from tablename;

How to be?
/**
     * @ORM\Column(type="geojson", options={"geometry_type"="MULTIPOLYGON", "srid"=3857})
     * @Groups({"GetTerritory", "CreateTerritory", "UpdateTerritory"})
     */
    private ?string $geom;

    /**
     * @ORM\Column(name="geom", type="geojson", options={"geometry_type"="MULTIPOLYGON", "srid"=3857})
     * @Groups({"GetTerritory", "CreateTerritory", "UpdateTerritory"})
     * @SerializedName("geom_text")
     */
    private ?string $geomAsText;


And is it even possible to do this in Entity, or will you have to get only one field, and already in another place "glue" the second field?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question