Code snippets

You will find here 12 code snippets I find useful so I don't have to Google ™ or Stackoverflow ™ them when I need. There are also code snippets I always forget! 😁 Sometimes, related links to the code will be available. The main difference with other random snippets you will find on the web is that in most cases (for the Symfony related ones) you will be able to run them directly from this website to check the output so you can verify it works as expected ™.

In this snippet, we see how to compute a virtual Doctrine entity's property after its loading. We use the postLoad Doctrine event....

Doctrine

Published on 2021-05-15 • Modified on 2021-05-15

 View the code


This is a Doctrine entity listener empty template for Symfony that you can copy-paste in your projects. I wanted to have it here o...

Doctrine

Published on 2021-04-26 • Modified on 2021-04-26

 View the code


In this snippet, we see how to retrieve a Doctrine entity's changeset after an update. This is essential to know when using Doctri...

Doctrine

Published on 2021-04-21 • Modified on 2021-04-21

 View the code


In this snippet, we will see how to test if a Doctrine entity has been modified from its initial state in the database. We must us...

Doctrine

Published on 2020-12-18 • Modified on 2020-12-18

 View the code


In this snippet, we will see how to get the fields and associations list of a Doctrine entity. First, we get the meta class of the...

Doctrine

Published on 2020-08-01 • Modified on 2020-08-01

 View the code


In this snippet, I will show you the changes I add to make on my configuration when I upgraded Doctrine Migrations from v2.x to v3...

Doctrine

Published on 2020-07-18 • Modified on 2020-07-18

 View the code


In this snippet we will see how to run raw SQL queries via the Doctrine DBAL connection instance. In the first example, we prepare...

Doctrine

Published on 2020-01-16 • Modified on 2020-01-16

 View the code


When having to process a large number of rows with Doctrine, it's not a good idea to use the standard getResult function as you ru...

Doctrine

Published on 2019-11-16 • Modified on 2019-11-27

 View the code


This is a small trick to avoid putting raw values in your Doctrine annotations. For example, it is useful when you have a length c...

Doctrine

Published on 2019-11-07 • Modified on 2019-11-07

 View the code


[Edit 2020-02-19] Please read my blog post on this topic. This is was my preferred way to declare and use Doctrine repositories. ...

Doctrine

Published on 2019-08-27 • Modified on 2020-02-17

 View the code