<tfoot id='zZA97'></tfoot>
    <legend id='zZA97'><style id='zZA97'><dir id='zZA97'><q id='zZA97'></q></dir></style></legend>
  • <small id='zZA97'></small><noframes id='zZA97'>

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

      1. Sequelize ORM中连接表的条件

        Where condition for joined table in Sequelize ORM(Sequelize ORM中连接表的条件)
        <legend id='W9CFm'><style id='W9CFm'><dir id='W9CFm'><q id='W9CFm'></q></dir></style></legend>
            <tbody id='W9CFm'></tbody>
            <bdo id='W9CFm'></bdo><ul id='W9CFm'></ul>

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

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

                • 本文介绍了Sequelize ORM中连接表的条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想用 sequelize ORM 得到这样的查询:

                  I want to get query like this with sequelize ORM:

                  SELECT "A".*,      
                  FROM "A" 
                  LEFT OUTER JOIN "B" ON "A"."bId" = "B"."id"
                  LEFT OUTER JOIN "C" ON "A"."cId" = "C"."id"
                  WHERE ("B"."userId" = '100'
                         OR "C"."userId" = '100')
                  

                  问题是续集不允许我在 where 子句中引用B"或C"表.以下代码

                  The problem is that sequelise not letting me to reference "B" or "C" table in where clause. Following code

                  A.findAll({
                      include: [{
                          model: B,
                          where: {
                              userId: 100
                          },
                          required: false
                  
                      }, {
                          model: C,
                          where: {
                              userId: 100
                          },
                          required: false
                      }]
                  ] 
                  

                  给我

                  SELECT "A".*,      
                  FROM "A" 
                  LEFT OUTER JOIN "B" ON "A"."bId" = "B"."id" AND "B"."userId" = 100
                  LEFT OUTER JOIN "C" ON "A"."cId" = "C"."id" AND "C"."userId" = 100
                  

                  这是完全不同的查询,结果是

                  which is completely different query, and result of

                  A.findAll({
                      where: {
                          $or: [
                              {'"B"."userId"' : 100},
                              {'"C"."userId"' : 100}
                          ]
                      },
                      include: [{
                          model: B,
                          required: false
                  
                      }, {
                          model: C,
                          required: false
                      }]
                  ] 
                  

                  甚至不是一个有效的查询:

                  is no even a valid query:

                  SELECT "A".*,      
                  FROM "A" 
                  LEFT OUTER JOIN "B" ON "A"."bId" = "B"."id"
                  LEFT OUTER JOIN "C" ON "A"."cId" = "C"."id"
                  WHERE ("A"."B.userId" = '100'
                         OR "A"."C.userId" = '100')
                  

                  sequelize 是否可以进行第一次查询,或者我应该坚持原始查询?

                  Is first query even possible with sequelize, or I should just stick to raw queries?

                  推荐答案

                  将引用连接表的列包装在 $$

                  Wrap the columns which reference joined tables in $$

                  A.findAll({
                      where: {
                          $or: [
                              {'$B.userId$' : 100},
                              {'$C.userId$' : 100}
                          ]
                      },
                      include: [{
                          model: B,
                          required: false
                  
                      }, {
                          model: C,
                          required: false
                      }]
                  }); 
                  

                  这篇关于Sequelize ORM中连接表的条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Pause youtube video, youtube api(暂停 youtube 视频,youtube api)
                  Youtube iframe api not triggering onYouTubeIframeAPIReady(Youtube iframe api 未触发 onYouTubeIframeAPIReady)
                  How can I stop a video with Javascript in Youtube?(如何在 Youtube 中停止使用 Javascript 的视频?)
                  How to call Greasemonkey#39;s GM_ functions from code that must run in the target page scope?(如何从必须在目标页面范围内运行的代码中调用 Greasemonkey 的 GM_ 函数?)
                  How do you mute an embedded Youtube player?(如何使嵌入式 Youtube 播放器静音?)
                  How to get number of video views with YouTube API?(如何使用 YouTube API 获取视频观看次数?)

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

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

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