I am a bit confused as to why Doctrine queries work in this certain way. Supposing that we have Articles and Users entities, with Users having a OneToMany relation with Articles.
Then, in the controller we'd get all the articles and send them to a view.
$em = $this->getEntityManager();
$articles = $em->getRepository('MyBundle:Article')->findAll();
And in the view we'd loop them.
{% for article in articles %}
{{ article.author.name }}
{% endfor %}
The problem here is that this piece of code does an additional query (for the article's user) for EVERY SINGLE ARTICLE.
I am aware that we can use DQL, but my question is how does Doctrine work here, why isn't it optimized for this kind of thing, which is pretty common? I find this to be a commonly used 'mistake' through applications, that really slows them down. I've just discovered this and now I have to rewrite so many queries into my controllers.
This also defeats the purpose of the ORM, which should actually provide speed in writing the application. This forces us to write DQL/QB queries instead of taking advantage of the ORM. So, when is the ORM a good idea to use if it performs so bad?