<tfoot id='VKrwy'></tfoot>

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

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

        <bdo id='VKrwy'></bdo><ul id='VKrwy'></ul>
      <legend id='VKrwy'><style id='VKrwy'><dir id='VKrwy'><q id='VKrwy'></q></dir></style></legend>

      1. 使用过多的 SQL 查询,doctrine2 加载具有 fetch 模式的一对多关联

        doctrine2 loads one-to-many associations with fetch mode eager using too many SQL queries(使用过多的 SQL 查询,doctrine2 加载具有 fetch 模式的一对多关联)
      2. <legend id='t1cGI'><style id='t1cGI'><dir id='t1cGI'><q id='t1cGI'></q></dir></style></legend>

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

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

                • 本文介绍了使用过多的 SQL 查询,doctrine2 加载具有 fetch 模式的一对多关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在加载一个包含许多实体的列表.
                  这些实体与其他实体之间存在一对多关联.
                  我想在一个 SQL 查询中加载所有这些其他实体(而不是对第一个列表中的每个实体进行一个查询).

                  I am loading a list of many entities.
                  These entities have a one-to-many association to other entities.
                  I want to load all these other entities in one single SQL query (instead of one query for every entity in the first list).

                  如doctrine2 文档所述:http://www.doctrine-project.org/docs/orm/2.1/en/reference/dql-doctrine-query-language.html#temporously-change-fetch-mode-in-dql 这应该可以通过EAGER"加载实现.

                  As discribed in the doctrine2 documentation: http://www.doctrine-project.org/docs/orm/2.1/en/reference/dql-doctrine-query-language.html#temporarily-change-fetch-mode-in-dql this should be possible with "EAGER" loading.

                  但它不像描述的那样工作.

                  but it does not work as described.

                  我的代码:

                  class User{
                      /**
                       * @ORMOneToMany(targetEntity="Address", mappedBy="user", indexBy="id", fetch="EAGER")
                       */
                      protected $addresses;
                      public function __construct(){
                          $this->addresses = new ArrayCollection();
                      }
                  }
                  
                  class Address{
                      /**
                       * @ORMManyToOne(targetEntity="User", inversedBy="addresses")
                       * @ORMJoinColumns({
                       *   @ORMJoinColumn(name="UserId", referencedColumnName="id")
                       * })
                       */
                      private $user;
                  }
                  
                  class UserRepository{
                      public function findUsersWithAddresses(){
                          return $this->getEntityManager()
                              ->createQuery('SELECT u FROM MyBundle:User u ORDER BY u.name ASC')
                              ->setFetchMode('MyBundleEntityUser', 'addresses', DoctrineORMMappingClassMetadata::FETCH_EAGER)
                              ->setMaxResults(10)
                              ->getResult();
                      }
                  }
                  

                  UserRepository::findUsersWithAddresses() 方法执行 11 个 SQL 查询.

                  The method UserRepository::findUsersWithAddresses() executes 11 SQL Queries.

                  如何告诉 Doctrine 只使用一个 SQL 查询来加载地址实体?

                  我正在使用:

                  • symfony v2.0.9
                  • 共同准则 2.1.4
                  • doctrine-dbal 2.1.5
                  • 教义 2.1.5

                  推荐答案

                  当前版本的学说不支持这个.

                  The current version of doctrine doesn't support this.

                  在doctrine2 问题跟踪器中有一个功能请求.

                  There is a feature request about this in the doctrine2 issue tracker.

                  所以我希望它能尽快实施.

                  So I hope it will be implemented soon.

                  这篇关于使用过多的 SQL 查询,doctrine2 加载具有 fetch 模式的一对多关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                  How to parse django style template tags(如何解析 django 样式模板标签)
                  What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                  How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                  What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                  php in background exec() function(php 后台 exec() 函数)

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

                    • <bdo id='Omd5g'></bdo><ul id='Omd5g'></ul>
                    • <legend id='Omd5g'><style id='Omd5g'><dir id='Omd5g'><q id='Omd5g'></q></dir></style></legend>

                          <tfoot id='Omd5g'></tfoot>

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