学说findBy在哪里和秩序

Sle*_*eek 0 php doctrine symfony doctrine-orm

我有一个关于symfony学说的片段,它按降序选择数据.尝试将where子句应用于某些等于true的字段是一个问题.以下是我的片段

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

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

上述尝试给出了错误

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

got*_*oto 7

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

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

findBy签名,如文档所述

findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
Run Code Online (Sandbox Code Playgroud)

  • 这是文档的链接以供参考:http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/working-with-objects.html#by-simple-conditions (2认同)