Hazte profesional con las consultas de Doctrine
Dive into Doctrine queries with this tutorial. Learn DQL, efficient use of JOINs, and specific field selection in Symfony!
- 1612 students
- EN/ES Captions
- EN/ES Script
- Certificate of Completion
Your Guides
About this course
Ya sabes hacer consultas con SQL, ¡así que aprender a hacer consultas complejas con Doctrine no debería ser un suplicio! En este tutorial, aprenderemos sobre:
- El lenguaje que habla Doctrine (DQL)
- El objeto
QueryBuilder
- Los JOIN Y cómo utilizarlos para reducir las consultas
- Seleccionar campos específicos en lugar de objetos enteros
- Si todo lo demás falla, ¡ejecuta consultas directas de SQL!
- Utilizando
Criteria
para filtrar eficazmente colecciones de relaciones
¡Y mucho más! ¡Veamos qué tipo de consultas locas podemos crear!
Next courses in the Symfony 6: Tools, Tools, Tools! section of the Symfony 6 Track!
8 Comments
Hey @Eric-N!
Good question! This tutorial is all about Doctrine, but we are absolutely working inside of Symfony. So the directory structure, bin/console commands (e.g. to generate migrations), and more will not translate. So, while I think you can still learn a lot about Doctrine in this course, you'll definitely need to do some translating to how that looks and works outside of Symfony. If you have any questions along the way, we'd be happy to do our best to answer them :).
Cheers!
Hey Lionel,
Unfortunately, no. But it should be the same DQL query in another DQL, this should work. But subqueries are mostly bad idea, sometimes it might be better (much better performance) to execute 2 separate queries. If you use subqueries - I would recommend you to profile those queries to see how long they are executing, then rewrite logic with 2 queries and compare. I bet in most cases 2 separate queries will be faster.
Cheers!
Great news! I would like to take this opportunity to share this article with you: https://soyuka.me/esql-alternative-to-doctrine-query-language-why/
Maybe it could give you some ideas 😇
The article is quite interesting. But try https://api-platform.com/docs/core/serialization/#embedding-relations . Probably you will achieve the same. If not, you would probably have to look at Doctrine and the Eager Loading. But I have to admit that in my first project with API Platform I encountered an unfavorable combination, combined with quite interesting bugs that e.g. made a difference on which platform the project was built... So I am not completly sure...
In combination with API-Platform it is explained here: https://api-platform.com/docs/core/performance/#eager-loading. There are multiple ways.
But I don't see an example for fetching an embedded relation one time with, and another without an eager collection, depending on the route.
For example you have customers with invoices, and each invoice has many products on it.
If you want to show an overview of the invoices you want to show all invoices and a number of positions, but not the product Detail-Data.
But if you want to show an invoice you want to show the invoices with the product data.
I think in this case, you can create a second getter, giving the exact same relation with another name and wihtout eager loading. In combination with https://api-platform.com/docs/core/serialization/#embedding-relations > Normalization Groups ( #[Groups('book')] ) even this should be possbile.
Hi,
I´m interested in this course but I´m using Mezzio instead of Symfony as PHP-Framework, so I would like to know if the things you learn in this course about Doctrine are framework independent ?