【问题标题】:Doctrine findBy where and order学说 findBy where and order
【发布时间】:2018-01-15 14:59:15
【问题描述】:

我有一个关于 symfony 原则的 sn-p,它按降序选择数据。尝试应用 where 子句某些字段等于 true 是一个问题。下面是我的sn-p

$results = $this->getDoctrine()->getRepository('RealBundle:Foo')->findBy([], ['id' => 'DESC','active' => true]); 

我有一个名为 active 的字段。检索所有 active 等于 true 的结果是一个挑战

上述尝试报错

按方向指定的顺序无效 RealBundle\Entity\Foo#active

【问题讨论】:

    标签: php symfony doctrine-orm doctrine


    【解决方案1】:

    试试这个
    $results = $doctrine->getRepository(Task::class) ->findBy(['active'=>true], ['id' => 'DESC']);

    【讨论】:

      【解决方案2】:

      第一个参数是WHERE子句,第二个参数是ORDER。

      $results = $this
        ->getDoctrine()
        ->getRepository('RealBundle:Foo')
        ->findBy(['active'=>true], ['id' => 'DESC']); 
      

      findBy 签名如the documentation 中所述

      findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
      

      【讨论】:

        猜你喜欢
        • 2014-05-08
        • 1970-01-01
        • 2016-10-16
        • 2012-03-04
        • 1970-01-01
        • 2018-06-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多