We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Working with Model and Postgis geometry

How do I save a record in a table that has a field of type geometry in postgres using Models? I used the Phalcon Tools to create the model but on insertion need to do: ST_GeomFromText ('POINT (48.432044 -71.060316)', 4326) for example. But how to do this in the Model? Once the interface will only send lat, lng for the service.

Sorry for English, do not know if I was clear.



93.7k
Accepted
answer

Hey friend, can you try with this:

$obj = new YourModel();
$obj->coords = new \Phalcon\Db\RawValue("GeomFromText('POINT(48.432044 -71.060316)', 0)");
$obj->save();

Good luck :)

Thanks, works fine =D

Hey friend, can you try with this:

$obj = new YourModel();
$obj->coords = new \Phalcon\Db\RawValue("GeomFromText('POINT(48.432044 -71.060316)', 0)");
$obj->save();

Good luck :)