3

I have a snippet on symfony doctrine that picks data in descending order. Attempting to Apply a where clause some fields it equal to true is a problem. Below is my snippet

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

I have a field called active. Retrieving all the results where active is equalto true is a challenge

The above attempt gives an error

Invalid order by orientation specified for RealBundle\Entity\Foo#active

goto
  • 7,908
  • 10
  • 48
  • 58
Sleek
  • 135
  • 2
  • 2
  • 9

2 Answers2

15

The first parameter is the WHERE clause, the second parameter is the ORDER.

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

findBy signature as described in the documentation

findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
goto
  • 7,908
  • 10
  • 48
  • 58
1

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