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 in Model

Hi guys!

$point = Point::find(array(
        'columns' => [
        'lat' => 'X(geopoint)',
        'lon' => 'Y(geopoint)',
    ]
));
print_r($point->toArray()); // Good, "lat" and "lon" isset
echo $poi->lat; // Bad, Notice undefined property $lat ...

Why?

edited Apr '16

No variable $poi and also Point::find() return array of points(in this case resultset), not single record.



19.7k
Accepted
answer

just use "columns" for profit

$poi = Poi::find(array(
        'conditions' => "INTERSECTS(geopoint, GeomFromText(?1))",
        'bind' => [
                1 => "POLYGON(($polyData))",
        ],
        'columns' => [
            'lon' => 'X(geopoint)',
            'lat' => 'Y(geopoint)',
            'title',
            'id',
            'address',
        ],
        'limit' => 20,
        'order' => 'rand()'
));