sejak product
Anda model ada di file terpisah, Anda harus mengimpornya menggunakan import
metode yang tersedia pada contoh sekuel sebagai berikut
model produk.js
module.exports = function(sequelize, Sequelize) {
const Product = sequelize.define('product', {
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
allowNull: false,
primaryKey: true
},
title: Sequelize.STRING,
price: {
type: Sequelize.DOUBLE,
allowNull: false
},
imageUrl: {
type: Sequelize.STRING,
allowNull: false
},
description: {
type: Sequelize.STRING,
allowNull: false
}
});
module.exports = Product;
};
dbconfig.js
const Sequelize = require('sequelize');
const sequelize = new Sequelize('node','root','1234567890', {
operatorsAliases: false ,
dialect: 'mysql',
host:'localhost'
});
sequelize.import('path/to/product/model');
module.exports = sequelize;
Referensi ikuti impor
Proyek Demo