We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.6k
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 :)