<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 优势的情况下降低查询数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                  <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>