I have a problem saving spatial data in CakePHP with saveAll(). I really dont want to write the query manually (Handling spatial data in CakePHP) because there are number of models being saved.
Also I read this CakePHP and MySQL Spatial Extension but when I try to do the same, $db->expression()
returns an stdClass.
This is the returned object printed out:
stdClass Object
(
[type] => expression
[value] => GeomFromText('POINT(48.18879 18.527579999999944)')
)
If I use this object the way it is used in CakePHP and MySQL Spatial Extension and try to save it with saveAll() I get this error:
Error: Cannot use object of type stdClass as array
File: /www/s/t/u47728/public_html/lib/Cake/Model/Model.php
Line: 2221
If I use the value property, it gets escaped in the query so it becomes just a string. Then I get this error:
Error: SQLSTATE[22003]: Numeric value out of range: 1416 Cannot get geometry object from data you send to the GEOMETRY field
Does saveAll() suport expressions?
UPDATE
Apparently the same applies to save() function and others.... Also saveField()
$this->data['Report']['position'] = (object) $db->expression("GeomFromText('POINT(" . $this->data['Report']['lat'] . " " . $this->data['Report']['lng'] . ")')");
and it worked. So marking your answer as accepted anyways because it lead me to the solution. Thank you very much – Dentil