Reputation: 145
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
Upvotes: 4
Views: 32318
Reputation: 873
try this
$results = $doctrine->getRepository(Task::class)
->findBy(['active'=>true], ['id' => 'DESC']);
Upvotes: 2
Reputation: 8164
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)
Upvotes: 17