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

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

    1. <tfoot id='sF4ZK'></tfoot>

      1. Doctin2 中的子查询 notIN 函数

        Subquery in doctrine2 notIN Function(Doctin2 中的子查询 notIN 函数)

          <tbody id='PRpf3'></tbody>

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

        <tfoot id='PRpf3'></tfoot>
            <bdo id='PRpf3'></bdo><ul id='PRpf3'></ul>

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

                • 本文介绍了Doctin2 中的子查询 notIN 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想选择不属于特定服务的成员.我有 3 张桌子:

                  I'd like to select members who are not in specific service. I have 3 tables :

                  • 成员
                  • 服务
                  • membre_service(membreservice 之间的关系)
                  • membre
                  • service
                  • membre_service (relation between membre and service)

                  我使用的是学说 2,在 SQL 中我的查询是:

                  I'm using doctrine 2 and in SQL my query is :

                  SELECT m.* FROM membre m WHERE m.`id` NOT IN (
                      SELECT ms.membre_id FROM membre_service ms WHERE ms.service_id != 29
                  )
                  

                  在 Doctrine 中,我这样做:

                  In Doctrine, I do :

                  $qb  = $this->_em->createQueryBuilder();
                  $qb2 = $qb;
                  $qb2->select('m.id')
                          ->from('CustomEntityMembreService', 'ms')
                          ->leftJoin('ms.membre', 'm')
                          ->where('ms.id != ?1')
                          ->setParameter(1, $service);
                  
                      $qb  = $this->_em->createQueryBuilder();
                      $qb->select('m')
                          ->from('CustomEntityMembre', 'm')
                          ->where($qb->expr()->notIn('m.id', $qb2->getDQL())
                      );
                      $query  = $qb->getQuery();
                      //$query->useResultCache(true, 1200, __FUNCTION__);
                  
                      return $query->getResult();
                  

                  我收到以下错误:

                  语义错误] line 0, col 123 near 'm WHERE ms.id': Error: 'm' is already defined.

                  Semantical Error] line 0, col 123 near 'm WHERE ms.id': Error: 'm' is already defined.

                  推荐答案

                  同一个查询中不能定义2次相同的别名

                  The same alias cannot be defined 2 times in the same query

                  $qb  = $this->_em->createQueryBuilder();
                  $qb2 = $qb;
                  $qb2->select('m.id')
                      ->from('CustomEntityMembreService', 'ms')
                      ->leftJoin('ms.membre', 'm')
                      ->where('ms.id != ?1');
                  
                  $qb  = $this->_em->createQueryBuilder();
                  $qb->select('mm')
                      ->from('CustomEntityMembre', 'mm')
                      ->where($qb->expr()->notIn('mm.id', $qb2->getDQL())
                  );
                  $qb->setParameter(1, $service);
                  $query  = $qb->getQuery();
                  
                  return $query->getResult();
                  

                  理想情况下,您应该为实体使用多对多关系,在这种情况下,您的查询会简单得多.

                  Ideally you should use many-to-many relation for your entity, in this case your query is going to be much simpler.

                  这篇关于Doctin2 中的子查询 notIN 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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='cty9I'></tbody>

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

                        • <bdo id='cty9I'></bdo><ul id='cty9I'></ul>

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