簡體   English   中英

如何排序代碼以連接兩個以上的表?

[英]How to sequlieze code to join more than two tables?

我有幾個表,我想通過使用sequelize來檢索數據。 這些表的架構如下所示:

幾個表的架構,包括“類別”,“子類別”,“用戶技能”,“用戶”和“用戶”

我想加入其中三個表,但出現錯誤號1054。

這是我的代碼:

技能模型:

    'use strict';
    module.exports=(sequelize,Datatypes)=>{
       const Skill=sequelize.define('userskills',{
      id:{type:Datatypes.INTEGER,autoincrement:true,primaryKey:true},
      Userid:{type:Datatypes.INTEGER,allowNull:false},
      Skill:{type:Datatypes.STRING,allowNull:false}
    });
       Skill.associate=(model)=>{
         Skill.belongsTo(model.User,{
           as:"User info",
           onDelete:"CASCADE",
           onUpdate:"CASCADE",
           foreignKey: 'Userid',
           targetKey:"id"
         });
         Skill.belongsTo(model.Subcategory,{
           as:"Skill info",
           onDelete:"CASCADE",
           onUpdate:"CASCADE",
           foreignKey:"Skillid",
           targetKey:"id"
         });
       };
       return Skill;
    };

該函數要求獲取數據:

    router.get('/',(req,res)=>{
      model.Skill.findAll({
        include:[{all:true}]
      }).then(result=>{
        res.status(200).json({
          result
        });
      }).catch(err=>{
        res.status(500).json({
          error:err
        });
      });
    });

您的ER圖似乎與Sequelizer模型對象不匹配……例如,技能名為“ Skillid”(模型)或“ Skillkey”(ER​​)的FK嗎?

要跟蹤SQL錯誤1054(未知col):在node.js日志中,找到Sequelizer從findAll生成的查詢,將其復制/粘貼到MySqlWorkbench並執行。 哪一列錯了?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM