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

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

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

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

        续集关联 - 请改用 promise 样式

        Sequelize associations - please use promise-style instead(续集关联 - 请改用 promise 样式)
      1. <i id='W3ybI'><tr id='W3ybI'><dt id='W3ybI'><q id='W3ybI'><span id='W3ybI'><b id='W3ybI'><form id='W3ybI'><ins id='W3ybI'></ins><ul id='W3ybI'></ul><sub id='W3ybI'></sub></form><legend id='W3ybI'></legend><bdo id='W3ybI'><pre id='W3ybI'><center id='W3ybI'></center></pre></bdo></b><th id='W3ybI'></th></span></q></dt></tr></i><div id='W3ybI'><tfoot id='W3ybI'></tfoot><dl id='W3ybI'><fieldset id='W3ybI'></fieldset></dl></div>
          <tbody id='W3ybI'></tbody>
        • <bdo id='W3ybI'></bdo><ul id='W3ybI'></ul>
          <legend id='W3ybI'><style id='W3ybI'><dir id='W3ybI'><q id='W3ybI'></q></dir></style></legend>

                <tfoot id='W3ybI'></tfoot>

                1. <small id='W3ybI'></small><noframes id='W3ybI'>

                  本文介绍了续集关联 - 请改用 promise 样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试将 3 个表连接在一起 ProductsSuppliersCategories,然后使用 SupplierID = 13.我已阅读

                  您现在应该执行以下样式:

                  db.Model.find(something).then(函数(结果){//对结果做一些事情//您也可以将结果进行另一个查询并返回承诺.返回 db.anotherModel.find(results[0].anotherModelId);}).then(函数(结果){//做其他事情}).catch(函数(错误){控制台日志(错误);}).finally(函数() {//finally 总是被调用,不管//承诺是否解决了错误.//然而这个 finally 处理程序不接收任何参数.});

                  简而言之:

                  使用 .then 代替 .success

                  使用 .catch 而不是 .error

                  使用 .finally 而不是 .done*注意:.finally 无论如何都会被调用.

                  I'm trying to join 3 tables together Products, Suppliers and Categories and then get row with SupplierID = 13. I have read How to implement many to many association in sequelize, there is explained how to associate 0:M.

                  DB model:

                  Code:

                  var Sequelize = require('sequelize')
                  var sequelize = new Sequelize('northwind', 'nodejs', 'nodejs', {dialect: 'mysql',})
                  var Project = require('sequelize-import')(__dirname + '/models', sequelize, { exclude: ['index.js'] });
                  
                  Project.Suppliers.hasMany(Project.Products, {foreignKey: 'SupplierID'});
                  Project.Products.belongsTo(Project.Suppliers, {foreignKey: 'SupplierID'});
                  Project.Categories.hasMany(Project.Products, {foreignKey: 'CategoryID'});
                  Project.Products.belongsTo(Project.Categories, {foreignKey: 'CategoryID'});
                  
                  Project.Products
                      .find({
                          where: {
                              SupplierID: 13
                          },
                          include: [
                              Project.Suppliers,
                              Project.Category,
                          ]
                      })
                      .success(function(qr){
                          if (qr == null) throw "Err";
                  
                          console.log("---");
                          console.log(qr);
                      })
                      .error(function(err){
                          console.log("Err");
                      });
                  

                  Log:

                      EventEmitter#success|ok is deprecated, please use promise-style instead.
                      EventEmitter#failure|fail|error is deprecated, please use promise-style instead.
                      Err
                  

                  解决方案

                  Update: 15 Jan 15 - added .finally() handler. Also indicated how .then() is being fed with an argument from the previous handler and how to perform the next sequenced query.

                  The .success, .error and .done handlers are deprecated. The errors are not critical and it is likely that backwards compatibility will be maintained on them. But you should still change it.

                  As per promise A specs: http://wiki.commonjs.org/wiki/Promises/A

                  You now should do the following style:

                  db.Model.find(something)
                    .then(function(results) {
                        //do something with results
                        //you can also take the results to make another query and return the promise.
                        return db.anotherModel.find(results[0].anotherModelId);          
                    }).then(function(results) {
                        //do something else
                    }).catch(function(err) {
                        console.log(err);
                    }).finally(function() {
                          // finally gets called always regardless of 
                          // whether the promises resolved with or without errors.
                          // however this finally handler does not receive any arguments.
                    });
                  

                  In short:

                  Use .then instead of .success

                  Use .catch instead of .error

                  Use .finally instead of .done *note: .finally will always get called regardless.

                  这篇关于续集关联 - 请改用 promise 样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 获取视频观看次数?)
                    <tbody id='0fguE'></tbody>
                  <i id='0fguE'><tr id='0fguE'><dt id='0fguE'><q id='0fguE'><span id='0fguE'><b id='0fguE'><form id='0fguE'><ins id='0fguE'></ins><ul id='0fguE'></ul><sub id='0fguE'></sub></form><legend id='0fguE'></legend><bdo id='0fguE'><pre id='0fguE'><center id='0fguE'></center></pre></bdo></b><th id='0fguE'></th></span></q></dt></tr></i><div id='0fguE'><tfoot id='0fguE'></tfoot><dl id='0fguE'><fieldset id='0fguE'></fieldset></dl></div>
                  <legend id='0fguE'><style id='0fguE'><dir id='0fguE'><q id='0fguE'></q></dir></style></legend>

                    <bdo id='0fguE'></bdo><ul id='0fguE'></ul>

                    <small id='0fguE'></small><noframes id='0fguE'>

                    • <tfoot id='0fguE'></tfoot>