Hello,
Im trying to convert this geolocator query from 2.5 to 3.0 orm but no luck so far.
CakePHP 2.5, this works fine:
$results = $this->find('all', array(
'limit' => 200,
'order' => array(
'distance' => 'ASC',
'name' => 'ASC',
),
'recursive' => -1,
'conditions' => "HAVING distance < $distance",
‘fields' => "*, TRUNCATE((3958 * 3.1415926 * SQRT((`lat` - {$lat}) * (`lat` - {$lat}) + COS(`lat` / 57.29578) * COS({$lat} / 57.29578) * (`lng` - {$lng}) * (`lng` - {$lng})) / 180) * {$unit}, 5) AS `distance`"
));
generated sql statement:
SELECT *, TRUNCATE((3958 * 3.1415926 * SQRT((`lat` - 34.0522) * (`lat` - 34.0522) + COS(`lat` / 57.29578) * COS(34.0522 / 57.29578) * (`lng` - -118.244) * (`lng` - -118.244)) / 180) * 1, 5) AS `distance` FROM `hockeypickup`.`locations` AS `Location` HAVING distance < 100 ORDER BY `distance` ASC, `name` ASC LIMIT 200
on CakePHP 3.0 this is far as I got :
$query = $this->find('all', array(
'limit' => 200,
'order' => array(
// 'distance' => 'ASC',
'name' => 'ASC',
),
'conditions' => $conditions,
'select' => "*, TRUNCATE((3958 * 3.1415926 * SQRT((`lat` - {$lat}) * (`lat` - {$lat}) + COS(`lat` / 57.29578) * COS({$lat} / 57.29578) * (`lng` - {$lng}) * (`lng` - {$lng})) / 180) * {$unit}, 5) AS Locations.distance",
// 'having' => "`distance` <= $distance",
));
distance is not getting recognized so far…
Thank you,
Andras
No comments:
Post a Comment