我有这两个模型
module.exports = function (sequelize, DataTypes) {
return sequelize.define('transportationType', {
description: {
type: DataTypes.STRING,
allowNull : false
}
})
}
module.exports = function (sequelize, DataTypes) {
return sequelize.define('Transportation', {
code: DataTypes.INTEGER,
description: DataTypes.STRING,
seatQty: DataTypes.INTEGER
})
}
这是关联
db.Transportation.belongsTo(db.TransportationType);
我制作了这样的api
var code = parseInt(req.body.code);
var desc = req.body.desc;
var seat = parseInt(req.body.seat);
var type = parseInt(req.body.TransportationType);
db.TransportationType.findById(type)
.then(snap => {
db.Transportation.setTransportationType(snap);
db.Transportation.create({
code: code,
description: desc,
seatQty: seat
})
.then(data => console.log(data))
.catch(err => res.json(err));
})
当我使用postman运行代码时,控制台说
db.Transportation.setTransportationType is not a function.
我确定文档会说它会运行,但不是