【问题标题】:Unhandled rejection TypeError: sequalize未处理的拒绝类型错误:续集
【发布时间】:2017-06-14 14:55:16
【问题描述】:

我在调用retrieveCart 函数时收到此错误? find all 查询中的错误是什么。我的 cartProducts 表中有一个名为 productID 的外键,由 sequelize 自动生成?

未处理的拒绝类型错误:无法读取属性“getTableName”的 未定义

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']}]
    })
}

【问题讨论】:

    标签: javascript node.js orm sequelize.js node-modules


    【解决方案1】:

    将modal:Product 改成model:Product,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-11
      • 2017-06-07
      • 1970-01-01
      • 1970-01-01
      • 2017-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多