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

Spatial point - mysql

Hi guys. Does anyone has an idea of how can i save a field as a spatial point using the built in ORM ? With plain sql i would just set it as GeomFromText('Point(LAT LON)'). But it seems this does not work. Maybe to set the field before saving and using the equivalent php function ?



98.9k

Try using a raw-value:

$p = new Point();
$p->point = new Phalcon\Db\RawValue('Point(LAT LON)');
$p->save();


51.2k

Thnks @Phalcon. It's working. Now, how can i get the point values. As X(point), Y(point) ? Should i use phql ?



51.2k

I am using raw sql as suggested https://docs.phalcon.io/en/latest/reference/phql.html . Can you please confirm that this is the right approach ? Wouldn't be more natural to allow defining the columns in the native find method ? like Robots::find('*','id=1') || Robots::find('name,type','id=1') that in plain sql would be select name, type from robots where id=1.



98.9k

You can pass a set of columns this way:

$robots = Robots::find(['id=1',  'columns' => 'name, type']);

https://docs.phalcon.io/en/latest/reference/models.html#finding-records



51.2k

:) thank you. it's working just fine