相关疑难解决方法(0)

Symfony2中的Doctrine2:如何查看哪个对象调用导致查询?

我正在使用Symfony2和Doctrine2.对于我的项目,我使用不同的关联映射创建了实体.首先,我确实看到了大约7个查询请求一个对象,所以我决定"急切加载",它减少到三个查询.

但是他们中的两个看起来在symfony工具栏(Profiler)中是相同的,直接相互调用.根据我的理解,我的代码中不需要第三个查询.

那么在哪里我必须在doctrine php文件中设置断点,看看我的代码哪一行让doctrine调用一个新的查询?或者是否有其他解决方案来了解我如何优化此请求?

更新:

在考虑了Artworkad的回答后,我必须更详细地了解.这是因为我没有通过我的控制器发出2个对象请求.但也许它与我的树枝有关?

我的控制器

public function gebietAction($gebiet){
        $em = $this->getDoctrine()->getEntityManager();
        /* @var $gebietobj Gebiet */
        $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));
    }
Run Code Online (Sandbox Code Playgroud)

我的树枝模板

{% 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 %}
Run Code Online (Sandbox Code Playgroud)

对象关联

Gebiet n:n Sektor与属性有关联.所以我Gebiet 1:n Gebietsektoren n:1 Sektor使用标准[doctrine2 association …

php mysql debugging symfony doctrine-orm

6
推荐指数
1
解决办法
1845
查看次数

标签 统计

debugging ×1

doctrine-orm ×1

mysql ×1

php ×1

symfony ×1