• <legend id='jNojr'><style id='jNojr'><dir id='jNojr'><q id='jNojr'></q></dir></style></legend>

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

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

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

      1. 续集多对多连接的位置

        时间:2023-09-04

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

                  <tbody id='8iAUV'></tbody>
                • <small id='8iAUV'></small><noframes id='8iAUV'>

                  <legend id='8iAUV'><style id='8iAUV'><dir id='8iAUV'><q id='8iAUV'></q></dir></style></legend>
                • 本文介绍了续集多对多连接的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我希望有人可以帮助我.我正在为 express.js 使用 Sequelize ORM,并且我在 2 个表之间有一个有效的多对多关系.

                  I am hoping somebody can help me. I am using the Sequelize ORM for express.js and I have a working many-to-many relationship between 2 tables.

                  为了简化我的查询,假设我的表是用户、书籍和用户书籍,其中用户书籍有用户 ID、书籍 ID 和一个附加列(假设它的 NoOfTimesRead).

                  For the sake of simplifying my query lets pretend my tables are Users, Books and UserBooks where UserBooks has UserId, BookId and an additional column (Lets say its NoOfTimesRead).

                  我想做的是这样的:

                  user.getBooks({
                    where: {
                      "userBooks.NoOfTimesRead": 0
                    }
                  });
                  

                  如果我输入:

                  user.getBooks();
                  

                  这有效并返回所有书籍,我只是无法弄清楚如何通过连接表上的附加列来查询它.

                  This works and returns all books, I just haven't been able to figure out how to query this by the additional column on the joining table.

                  我希望这是有道理的,

                  感谢观看!

                  推荐答案

                  使用 Belongs-To-Many,您可以基于直通关系和选择特定属性.例如将 findAll 与 through 一起使用

                  With Belongs-To-Many you can query based on through relation and select specific attributes. For example using findAll with through

                  User.findAll({
                    include: [{
                      model: Project,
                        through: {
                          attributes: ['createdAt', 'startedAt', 'finishedAt']
                            where: {completed: true}
                        }
                     }] 
                   });
                  

                  基本上你可以使用 through 选项和 include 你链接的关系.更多信息请参见这里

                  Basically you can use through option and include the relationship that you linked. More can be found here

                  这篇关于续集多对多连接的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 sequelize 根据 express.js 中的路由更改数据库连接 下一篇:[NodeJs][Sequelize] ReferenceError:初始化前无法访问“ModelName"

                  相关文章

                  <legend id='74x2m'><style id='74x2m'><dir id='74x2m'><q id='74x2m'></q></dir></style></legend>

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

                  <tfoot id='74x2m'></tfoot>
                • <small id='74x2m'></small><noframes id='74x2m'>

                        <bdo id='74x2m'></bdo><ul id='74x2m'></ul>