I’m trying to migrate a sql-query to work in cakephp 4:
SELECT name
FROM streets
WHERE ST_CONTAINS(@area,linestring
);
This query is giving the expected results when run in a terminal.
According to https://book.cakephp.org/4/en/orm/database-basics.html I’m using the ‘execute’ command:
execute(‘SELECT name
FROM streets
WHERE ST_CONTAINS(:area,linestring
)’,[‘area’ => $polygon])
The ‘execute’ takes the $polygon as a string, so I have to bind the wanted datatype, which shoud be ‘geometry’ I think.
execute(‘SELECT name
FROM streets
WHERE ST_CONTAINS(:area,linestring
)’,[‘area’ => $polygon][‘polygon’ => ‘geometry’])
‘Geometry’ isn’t a supported datatype (https://book.cakephp.org/4/en/orm/database-basics.html#data-types).
Searching the github, there are some closed issues concerning geospatial datatypes. They end up ‘closed’ with a reference to https://book.cakephp.org/4/en/orm/database-basics.html#adding-custom-types.
Before even starting to try to get a custom data type ‘geometry’:
- Is the line of thought correct, or do I have to search in another direction?
- Did anybody else develope the geometry-datatype, code I can copy?
- Although it looks a bit complicated to me, is developing a custom-datatype straightforward following the ‘json’-example in the cookbook?