sequelize包括不返回数据

时间:2019-07-25 09:59:50

标签: node.js sequelize.js

我试图从2个表viz-skillsrepo和认证中获取与empid映射的数据,并将其呈现到前端,我从认证表中获取所有数据,但是我只需要我在请求中发送的empid的数据

尝试使用包含方法

app.get('/updateprofile/:id', function (req, res) {
  db.skillsrepo.find({
    where: { employeeId: req.params.id },
    include: [
      {
        model: db.certifications
      },
      {
        model: db.attachments
      },
      {
        model: db.project
      }
    ]
  }).then(result => {
    if (result != null) {
      res.render('updateprofile', {
        user: result,
        eid: req.params.id,

      });
      console.log("**********", result)
    }
  })
});

这是架构:

var skillsrepo = exports.skillsrepo = connection.define('skillsrepo', {
  firstname: {
    type: Sequelize.STRING(23)
  },
  lastname: {
    type: Sequelize.STRING(23)
  },
  highQual: {
    type: Sequelize.STRING(23)
  },
  fivekeystrenghts: {
    type: Sequelize.TEXT
  },
  domain: {
    type: Sequelize.STRING(23)
  },
  technicalskills: {
    type: Sequelize.STRING(23)
  },
  typesoftesting: {
    type: Sequelize.STRING(23)
  },
  employeeId: {
    type: Sequelize.INTEGER(11),
    references: {
      model: 'employeemastertablee',
      key: 'id'
    }
  }
});

skillsrepo.hasMany(certifications, {
  foreignKey: "employeeId"
});

certifications.belongsTo(skillsrepo, {
  foreignKey: "employeeId"
});

0 个答案:

没有答案