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

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

        <bdo id='Ex1QA'></bdo><ul id='Ex1QA'></ul>

        <legend id='Ex1QA'><style id='Ex1QA'><dir id='Ex1QA'><q id='Ex1QA'></q></dir></style></legend>
        <tfoot id='Ex1QA'></tfoot>

        Doctrine 2 限制与 DQL 的关联

        Doctrine 2 Restricting Associations with DQL(Doctrine 2 限制与 DQL 的关联)
        <tfoot id='afgts'></tfoot>
          <tbody id='afgts'></tbody>

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

          <legend id='afgts'><style id='afgts'><dir id='afgts'><q id='afgts'></q></dir></style></legend>

              <bdo id='afgts'></bdo><ul id='afgts'></ul>
                <i id='afgts'><tr id='afgts'><dt id='afgts'><q id='afgts'><span id='afgts'><b id='afgts'><form id='afgts'><ins id='afgts'></ins><ul id='afgts'></ul><sub id='afgts'></sub></form><legend id='afgts'></legend><bdo id='afgts'><pre id='afgts'><center id='afgts'></center></pre></bdo></b><th id='afgts'></th></span></q></dt></tr></i><div id='afgts'><tfoot id='afgts'></tfoot><dl id='afgts'><fieldset id='afgts'></fieldset></dl></div>
                  本文介绍了Doctrine 2 限制与 DQL 的关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 Doctrine 2.1 中似乎有一个问题,返回子集并不容易为协会收集.

                  There seems to be an over sight in Doctrine 2.1 where it isn't easy to return a subset collection for an association.

                  http://www.doctrine-project.org/docs/orm/2.1/en/reference/limitations-and-known-issues.html#restricting-associations

                  文档建议编写存储库查找方法,这是有道理的,因为这是我想做的第一件事.

                  The docs recommend to write a repository find method, which makes sense because that was the first thing I though of doing.

                  但是,如果没有对实体内的 EntityManager 的引用,我看不出您将如何检索关联的存储库,这似乎违背了将域与数据库分离的意义?

                  However without having a reference to the EntityManager within an Entity I can't see how you would retrieve the association's Repository and this seems to defeat the point of separating the Domain from the Database?

                  是否有针对此问题的推荐策略?

                  Is there a recommended strategy for this problem?

                  这是我对他们建议的解决方案的解释.

                  Here is my interpretation of their suggested solution.

                  class Category
                  {
                      protected $id;
                      protected $articles; // PesistentCollection
                      protected $em; // The EntityManager from somewhere?
                  
                      public function getVisableArticles()
                      {
                          return $this->em->getRepository('Article')
                                      ->getVisibleByCategory($this);
                      }
                  }
                  

                  推荐答案

                  1. 在实体中使用 entitymanager 在任何情况下都不是一件好事(改为注入您的存储库)
                  2. 类别不是文章的唯一根,因为它无法确定您需要哪些文章,因此您需要一个文章存储库.

                  我会怎么做:

                  class Category
                  {
                      protected $id;
                      protected $articles; // PesistentCollection
                  
                      public function getVisableArticles(IArticleRepository $articleRepository)
                      {
                          return $articleRepository->getVisibleByCategory($this);
                      }
                  }
                  
                  interface IArticleRepository
                  {
                      function getVisibleByCategory(Category $category);
                  }
                  

                  您的学说的存储库将实现 IArticleRepository,而该类将不知道您的数据存储/学说的任何信息.

                  Your doctrine's repository would implement IArticleRepository and the class won't know anything about your data storage/doctrine.

                  这篇关于Doctrine 2 限制与 DQL 的关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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() 函数)
                  <i id='zOk5Q'><tr id='zOk5Q'><dt id='zOk5Q'><q id='zOk5Q'><span id='zOk5Q'><b id='zOk5Q'><form id='zOk5Q'><ins id='zOk5Q'></ins><ul id='zOk5Q'></ul><sub id='zOk5Q'></sub></form><legend id='zOk5Q'></legend><bdo id='zOk5Q'><pre id='zOk5Q'><center id='zOk5Q'></center></pre></bdo></b><th id='zOk5Q'></th></span></q></dt></tr></i><div id='zOk5Q'><tfoot id='zOk5Q'></tfoot><dl id='zOk5Q'><fieldset id='zOk5Q'></fieldset></dl></div>
                    <legend id='zOk5Q'><style id='zOk5Q'><dir id='zOk5Q'><q id='zOk5Q'></q></dir></style></legend>
                    <tfoot id='zOk5Q'></tfoot>
                      <bdo id='zOk5Q'></bdo><ul id='zOk5Q'></ul>

                      1. <small id='zOk5Q'></small><noframes id='zOk5Q'>

                          <tbody id='zOk5Q'></tbody>