PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, March 12, 2022

[FIXED] Doctrine findBy where and order

 March 12, 2022     doctrine, doctrine-orm, php, symfony     No comments   

Issue

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


Solution

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)


Answered By - goto
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing