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

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

  • <small id='qhswQ'></small><noframes id='qhswQ'>

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

      1. 在 Symfony2/Doctrine SQL 中使用 JOIN

        Using JOIN in Symfony2/Doctrine SQL(在 Symfony2/Doctrine SQL 中使用 JOIN)
        • <i id='wLdhU'><tr id='wLdhU'><dt id='wLdhU'><q id='wLdhU'><span id='wLdhU'><b id='wLdhU'><form id='wLdhU'><ins id='wLdhU'></ins><ul id='wLdhU'></ul><sub id='wLdhU'></sub></form><legend id='wLdhU'></legend><bdo id='wLdhU'><pre id='wLdhU'><center id='wLdhU'></center></pre></bdo></b><th id='wLdhU'></th></span></q></dt></tr></i><div id='wLdhU'><tfoot id='wLdhU'></tfoot><dl id='wLdhU'><fieldset id='wLdhU'></fieldset></dl></div>

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

              <tbody id='wLdhU'></tbody>
            <legend id='wLdhU'><style id='wLdhU'><dir id='wLdhU'><q id='wLdhU'></q></dir></style></legend>

            1. <tfoot id='wLdhU'></tfoot>
                <bdo id='wLdhU'></bdo><ul id='wLdhU'></ul>

                  本文介绍了在 Symfony2/Doctrine SQL 中使用 JOIN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在尝试使用 QueryBuilder 或 DQL 时遇到问题.

                  I have a problem while trying to USE QueryBuilder OR DQL.

                  我有以下关系:

                  用户 <-1:n-> 配置文件 <-n:m-> RouteGroup <-1:n-> Route

                  User <-1:n-> Profile <-n:m-> RouteGroup <-1:n-> Route

                  我想制作一个 DQL,列出特定用户可以访问的所有路由.我可以使用以下代码获取此信息:

                  I would like to make a DQL that lists all the routes that a specific user has access. I can get this information with the following code:

                  $usr = $this->container->get('security.context')->getToken()->getUser();
                  foreach ($usr->getProfiles() as $profile){
                      foreach ($profile->getRoutegroups() as $routegroup){
                          var_dump($routegroup->getRoutes()->toArray());
                       }
                  }
                  

                  出于显而易见的原因,我不能使用此代码,否则我的服务器会超载,哈哈.

                  For obvious reason i cant use this code, otherwise I will overload my server, LOL.

                  我尝试了以下方法:

                  DQL:

                  $em->createQuery('SELECT p FROM CRMCoreBundle:User u
                                    JOIN CRMCoreBundle:Profile p
                                    JOIN CRMCoreBundle:RoleGroup rg
                                    JOIN CRMCoreBundle:Role r
                                    WHERE
                                      u.id=:user')
                          ->setParameter('user', $user->getId())
                          ->getResult();
                  

                  QueryBuilder(我尝试使用 u.profiles - 关系的名称而不是实体的名称 - 但这也不起作用):

                  QueryBuilder (i tried using u.profiles - the name of the relationship instead of the entity - but this did not work also):

                  $em->createQueryBuilder()
                          ->select('r')
                          ->from('CRMCoreBundle:User', 'u')
                          ->innerJoin('u.profiles','p')
                          ->where('u.id = :user_id')
                          ->setParameter('user_id', $user->getId())
                          ->getQuery()
                          ->getResult();
                  

                  有人可以帮忙吗???

                  更新:我尝试了 Zeljko 的解决方案并制作了这个脚本:

                      return $this->getEntityManager()
                          ->createQueryBuilder()
                          ->select('u, r')
                          ->from('CRMCoreBundle:User', 'u')
                          ->innerJoin('u.profiles','p')
                          ->innerJoin('p.routegroups','rg')
                          ->innerJoin('rg.routes','r')
                          ->where('u.id = :user_id')->setParameter('user_id', $user->getId())
                          ->getQuery()
                          ->getResult();
                  

                  但我得到了这个错误:

                  The parent object of entity result with alias 'r' was not found. The parent alias is 'rg'.
                  

                  如果我将->select('u, r')"更改为->select('r')",我会得到:

                  If i change "->select('u, r')" to "->select('r')" i get this:

                  [Semantical Error] line 0, col -1 near 'SELECT r FROM': Error: Cannot select entity through identification variables without choosing at least one root entity alias.
                  

                  推荐答案

                  在尝试了一些替代方案后,我发现我可以进行反向查找,从路由到用户.解决方法如下:

                  After trying some alternatives I found out that I could make an inverse lookup, starting from routes to users. The solution was as follows:

                  return $this->getEntityManager()
                          ->createQueryBuilder()
                          ->select('r')
                          ->from('CRMCoreBundle:Route', 'r')
                          ->innerJoin('r.routegroup','rg')
                          ->innerJoin('rg.profiles','p')
                          ->innerJoin('p.users','u')
                          ->where('u.id = :user_id')
                          ->setParameter('user_id', $user->getId())
                          ->getQuery()
                          ->getResult();
                  

                  这篇关于在 Symfony2/Doctrine SQL 中使用 JOIN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的问题)
                  • <tfoot id='1S7I2'></tfoot>

                        <bdo id='1S7I2'></bdo><ul id='1S7I2'></ul>
                        1. <small id='1S7I2'></small><noframes id='1S7I2'>

                              <tbody id='1S7I2'></tbody>

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

                            <legend id='1S7I2'><style id='1S7I2'><dir id='1S7I2'><q id='1S7I2'></q></dir></style></legend>