Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine findBy 'does not equal'

Tags:

doctrine-orm

How do I do

WHERE id != 1 

In Doctrine?

I have this so far

$this->getDoctrine()->getRepository('MyBundle:Image')->findById(1); 

But how do I do a "do not equals"?

This maybe daft, but I cannot find any reference to this?

Thanks

like image 625
Jake N Avatar asked Dec 29 '12 21:12

Jake N


1 Answers

There is now a an approach to do this, using Doctrine's Criteria.

A full example can be seen in How to use a findBy method with comparative criteria, but a brief answer follows.

use \Doctrine\Common\Collections\Criteria;  // Add a not equals parameter to your criteria $criteria = new Criteria(); $criteria->where(Criteria::expr()->neq('prize', 200));  // Find all from the repository matching your criteria $result = $entityRepository->matching($criteria); 
like image 89
El Yobo Avatar answered Sep 28 '22 04:09

El Yobo