I am using Symfony2 with Doctrine2. For my project, I created objects with a different association mapping. At first, I looked at about 7 requests to request a single object, so I decided to make an “impatient download” and reduced to three requests.
But two of them look the same on the symfony toolbar (Profiler), which are directly called one after another. In my opinion, my code does not need a third request.
So where should I set my breakpoints in doctrine php files to see which line of my code does the doctrine causing a new request? Or is there another solution to see how I can optimize these queries?
Update:
After thinking about Artworkad's answer, I have to go in much more detail. This is due to the fact that I do not make 2 object requests through my controller. But maybe this has something to do with my branch?
My controller
public function gebietAction($gebiet){
$em = $this->getDoctrine()->getEntityManager();
$gebietobj = $em->getRepository('ACGSigwxBundle:Gebiet')->findOneBy(array('short' => $gebiet));
if (!$gebietobj) {
throw $this->createNotFoundException('Kann das angegebene Gebiet nicht finden!');
}
return $this->render('ACGSigwxBundle:Sigwx:sigwx.html.twig',array("gebiet"=>$gebietobj));
}
My Twig Template
{% extends "ACGSigwxBundle::layout.html.twig" %}
{% block content %}
<h1>{{ gebiet.getName() }}</h1>
<p>My sectors:</p>
<ul>
{% for gs in gebiet.getGebietssektoren() %}
<li>{{ gs.getSektor().getName() }}</li>
{% endfor %}
</ul>
{% endblock %}
Object Association
There is an association Gebiet n:n Sektorwith attributes. So I did Gebiet 1:n Gebietsektoren n:1 Sektorwith the standard [doctrine2 association associations ( http://docs.doctrine-project.org/en/latest/reference/association-mapping.html ) ManyToOneandOneToMany
My 3 listed requests from the profiler
SELECT t0.id AS id1, t0.name AS name2, t0.short AS short3, t0.parent_id AS parent_id4 FROM gebiet t0 WHERE t0.short = ? LIMIT 1 Parameters: [app]
SELECT t0.id AS id1, t0.position AS position2, t0.size AS size3, t0.gebiet_id AS gebiet_id4, t0.sektor_id AS sektor_id5, t6.id AS id7, t6.name AS name8, t6.typ AS typ9, t6.erweitert AS erweitert10, t6.sortorder AS sortorder11 FROM gebietssektoren t0 INNER JOIN sektor t6 ON t0.sektor_id = t6.id WHERE t0.gebiet_id = ? Parameters: [1]
SELECT t0.id AS id1, t0.position AS position2, t0.size AS size3, t0.gebiet_id AS gebiet_id4, t0.sektor_id AS sektor_id5, t6.id AS id7, t6.name AS name8, t6.typ AS typ9, t6.erweitert AS erweitert10, t6.sortorder AS sortorder11 FROM gebietssektoren t0 INNER JOIN sektor t6 ON t0.sektor_id = t6.id WHERE t0.gebiet_id = ? Parameters: [1]