<tfoot id='2FRc1'></tfoot>
    <legend id='2FRc1'><style id='2FRc1'><dir id='2FRc1'><q id='2FRc1'></q></dir></style></legend>

        <small id='2FRc1'></small><noframes id='2FRc1'>

          <bdo id='2FRc1'></bdo><ul id='2FRc1'></ul>
      1. <i id='2FRc1'><tr id='2FRc1'><dt id='2FRc1'><q id='2FRc1'><span id='2FRc1'><b id='2FRc1'><form id='2FRc1'><ins id='2FRc1'></ins><ul id='2FRc1'></ul><sub id='2FRc1'></sub></form><legend id='2FRc1'></legend><bdo id='2FRc1'><pre id='2FRc1'><center id='2FRc1'></center></pre></bdo></b><th id='2FRc1'></th></span></q></dt></tr></i><div id='2FRc1'><tfoot id='2FRc1'></tfoot><dl id='2FRc1'><fieldset id='2FRc1'></fieldset></dl></div>
      2. Symfony 2/Doctrine:如何在不失去 ORM 优势的情况下降低查询数量?

        Symfony 2/Doctrine: How to lower the num of queries without losing the benefit of ORM?(Symfony 2/Doctrine:如何在不失去 ORM 优势的情况下降低查询数量?)
      3. <i id='JoWjl'><tr id='JoWjl'><dt id='JoWjl'><q id='JoWjl'><span id='JoWjl'><b id='JoWjl'><form id='JoWjl'><ins id='JoWjl'></ins><ul id='JoWjl'></ul><sub id='JoWjl'></sub></form><legend id='JoWjl'></legend><bdo id='JoWjl'><pre id='JoWjl'><center id='JoWjl'></center></pre></bdo></b><th id='JoWjl'></th></span></q></dt></tr></i><div id='JoWjl'><tfoot id='JoWjl'></tfoot><dl id='JoWjl'><fieldset id='JoWjl'></fieldset></dl></div>
        <legend id='JoWjl'><style id='JoWjl'><dir id='JoWjl'><q id='JoWjl'></q></dir></style></legend>

        <small id='JoWjl'></small><noframes id='JoWjl'>

            <bdo id='JoWjl'></bdo><ul id='JoWjl'></ul>
                  <tbody id='JoWjl'></tbody>
                • <tfoot id='JoWjl'></tfoot>

                  本文介绍了Symfony 2/Doctrine:如何在不失去 ORM 优势的情况下降低查询数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我使用 Symfony 2.7Doctrine.我的控制器操作通常如下所示:

                  I'm using Symfony 2.7 with Doctrine. My controller actions often look like:

                  # my/namespace/Controller/ItemsController.php -> listAction()
                  
                  $items = $this->get('repository.items')->findAll();
                  return $this->render('itemsList.html.twig', array('items' => $items));
                  

                  在我的模板中,我喜欢迭代关联实体:

                  In my templates I like to iterate associated Entities:

                  # my/namespace/Resources/views/itemsList.html.twig
                  
                  {% for item in items %}
                      Item: {{ item.name }} <br/>
                      Groups: <br/>
                      <ul>
                      {% for group in item.groups %}
                          <li>{{ group.name }}</li>
                      {% endfor %}
                      </ul>
                  {% endfor %}
                  

                  这会导致许多 SELECT 查询,我想避免这种情况.到目前为止,我知道的唯一解决方案是在 repository 中收集所有需要的数据并在 action 中分配它,而不是在模板中爬行.

                  This causes many SELECT-queries, which I'd like to avoid. The only solution I know so far is collecting all needed data in a repository and assigning it in the action, instead of crawling within the template.

                  我想保持它在树枝片段中看到的那样.是否有任何智能缓存选项可以检测像我这样的情况并自动优化查询?

                  I'd like to keep it that way as seen in the twig-snippet. Are there any smart caching options that might detect cases like mine and optimize the queries automatically?

                  提前致谢!

                  推荐答案

                  正如其他人所说,您应该在您的存储库中获取组实体.你可以使用这样的东西:

                  As other's have said, you should fetch the group Entities inside your repository. You can use something like this:

                  //inside the repository
                  public function findAllFetchGroups(){
                  
                    return $this->createQueryBuilder('a')
                      ->addSelect('gs')->join('a.groups', 'gs')
                      ->getQuery()->getResult();
                  }
                  

                  这篇关于Symfony 2/Doctrine:如何在不失去 ORM 优势的情况下降低查询数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Proxy Authentication Required with cURL(cURL 需要代理身份验证)
                  How to use a SOCKS 5 proxy with cURL?(如何使用带有 cURL 的 SOCKS 5 代理?)
                  How to use HTTP_X_FORWARDED_FOR properly?(如何正确使用 HTTP_X_FORWARDED_FOR?)
                  file_get_contents behind a proxy?(代理后面的 file_get_contents ?)
                  pecl install cassandra throws: quot;error: Unable to load libcassandraquot;(pecl install cassandra 抛出:“错误:无法加载 libcassandra)
                  Installing php datastax driver on ubuntu(在 ubuntu 上安装 php datastax 驱动)

                  <small id='JB2fa'></small><noframes id='JB2fa'>

                  • <legend id='JB2fa'><style id='JB2fa'><dir id='JB2fa'><q id='JB2fa'></q></dir></style></legend>

                      1. <tfoot id='JB2fa'></tfoot>
                          <bdo id='JB2fa'></bdo><ul id='JB2fa'></ul>
                          <i id='JB2fa'><tr id='JB2fa'><dt id='JB2fa'><q id='JB2fa'><span id='JB2fa'><b id='JB2fa'><form id='JB2fa'><ins id='JB2fa'></ins><ul id='JB2fa'></ul><sub id='JB2fa'></sub></form><legend id='JB2fa'></legend><bdo id='JB2fa'><pre id='JB2fa'><center id='JB2fa'></center></pre></bdo></b><th id='JB2fa'></th></span></q></dt></tr></i><div id='JB2fa'><tfoot id='JB2fa'></tfoot><dl id='JB2fa'><fieldset id='JB2fa'></fieldset></dl></div>
                            <tbody id='JB2fa'></tbody>