Unhandled rejection TypeError: sequalize
Unhandled rejection TypeError: sequalize
我在调用 retrieveCart 函数时遇到此错误? find all 的查询错误是什么。我的 cartProducts table?
中有一个由 sequelize 自动生成的名为 productID 的外键
Unhandled rejection TypeError: Cannot read property 'getTableName' of
undefined
const Product = db.define('products', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
name: Sequelize.STRING,
price: Sequelize.INTEGER,
pic: Sequelize.STRING
});
const Cart = db.define('cartProduct',{
cid: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
qty:{
type:Sequelize.INTEGER,
defaultValue:1
}
});
Product.sync({}).then(()=>{
Cart.belongsTo(Product);
Cart.sync({});
Product.destroy({
where:{}
});
Cart.destroy({
where:{}
});
console.log("DataBase Created");
var i ,len = products.length;
for(i=0;i<len;i++){
Product.create({
id:i+1,
name: products[i].name,
price: products[i].price,
pic: products[i].img
}).then(()=>{
console.log("Data Inserted");
});
}
});
function retrieveCart() {
return Cart.findAll({
include:[{
modal:Product,
attributes:['name','price']}]
})
}
将 modal:Product
更正为 model:Product,
我在调用 retrieveCart 函数时遇到此错误? find all 的查询错误是什么。我的 cartProducts table?
中有一个由 sequelize 自动生成的名为 productID 的外键Unhandled rejection TypeError: Cannot read property 'getTableName' of undefined
const Product = db.define('products', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
name: Sequelize.STRING,
price: Sequelize.INTEGER,
pic: Sequelize.STRING
});
const Cart = db.define('cartProduct',{
cid: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
qty:{
type:Sequelize.INTEGER,
defaultValue:1
}
});
Product.sync({}).then(()=>{
Cart.belongsTo(Product);
Cart.sync({});
Product.destroy({
where:{}
});
Cart.destroy({
where:{}
});
console.log("DataBase Created");
var i ,len = products.length;
for(i=0;i<len;i++){
Product.create({
id:i+1,
name: products[i].name,
price: products[i].price,
pic: products[i].img
}).then(()=>{
console.log("Data Inserted");
});
}
});
function retrieveCart() {
return Cart.findAll({
include:[{
modal:Product,
attributes:['name','price']}]
})
}
将 modal:Product
更正为 model:Product,