Symfony2, Doctrine search and order by distance

邮差的信 提交于 2019-12-01 18:33:35
    $d = $this->getDoctrine()->getRepository('XXXWebsiteBundle:Locations')->createQueryBuilder('l');
    $d
        ->select('l')
        ->addSelect(
            '( 3959 * acos(cos(radians(' . $latitude . '))' .
                '* cos( radians( l.latitude ) )' .
                '* cos( radians( l.longitude )' .
                '- radians(' . $longitude . ') )' .
                '+ sin( radians(' . $latitude . ') )' .
                '* sin( radians( l.latitude ) ) ) ) as distance'
        )
        ->andWhere('l.enabled = :enabled')
        ->setParameter('enabled', 1)
        ->having('distance < :distance')
        ->setParameter('distance', $requestedDistance)
        ->orderBy('distance', 'ASC');

You are using andWhere() without a where().

Replace the andWhere() with a where().

Please check also in your Entity definition if some property is mapped on a column called "sclr21", so you can discovery also on which property do you have the issue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!