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.

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.



7.0k
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()'
));