• <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 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的问题)
                    <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>