【问题标题】:OrderBy calculate propritie EntityOrderBy 计算专有实体
【发布时间】:2013-12-03 14:32:30
【问题描述】:

实体:

 class Pharmacie{    
      public $distance;

     public function getDistance() {
          // calculate distance here 
          return $distance; 
    }

}

在控制器中:

 public function listePharmsGeoAction()
{
    $em = $this->getDoctrine()->getEntityManager();


    $pharmas = $em->getRepository('CentraleFrontBundle:Pharmacie')
                   ->createQueryBuilder('o')
                   ->orderBy('o.distance','ASC')
                   ->getQuery()
                   ->getResult();



     return $this->render('CentraleFrontBundle:SiteFront:listePharms.html.twig', array(
        'pharmas' => $pharmas));
}

错误:[语义错误] line 0, col 65 near 'distance ASC':错误:Class Centrale\FrontBundle\Entity\Pharmacie 没有名为 distance 的字段或关联

【问题讨论】:

  • 您的 Pharmacie 实体中没有距离属性...问题是什么?

标签: symfony doctrine-orm entitymanager


【解决方案1】:
  • 直接在控制器中创建查询是一种不好的做法,您应该在存储库中创建函数
  • 距离财产应该受到保护或私有而不是公共
  • 你的映射在哪里???

【讨论】:

  • 认为你的响应蝙蝠距离没有表列映射是用地址和 ip 字段计算
  • 好的,这很正常,不能按不存在的列排序。
  • 我如何通过计算适当性来订购?
猜你喜欢
  • 2011-11-21
  • 2020-06-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多