Doctrine — DQL functions cheat-sheet

Doctrine Query Language provides a lot of unknown yet powerful built-in functions

Alexandre Daubois
Geek Culture

--

Used in the vast majority of cases with Symfony, Doctrine is a really powerful ORM, packed with a language called DQL (Doctrine Query Language). This language gives you an extra layer of abstraction from your database system. Unfortunately, it is a bit marred by a sometimes complicated documentation. This is maybe subjective. However, because of this, I was still unaware of many of the features I’m going to present in this article until now. Yet, these functions would have been useful to me many times in my career as a developer. Let’s have a look at the main ones.

For the rest of this article, we’ll use a simple model, composed of multiple Users, which can belong to only one Group each. Users can have roles, an email, an address and an expiration date.

MEMBER OF

Let’s start with an function that will help you a lot when dealing with collections. You probably heard about the IN operator in SQL/DQL, using it for example like this:

--

--

Alexandre Daubois
Geek Culture

Lead Developer at Wanadev // Open-source contributor