I'm learnig how to use Sequelize for a Node.JS project, I'm working on the models:
index.js
var Sequelize = require('sequelize');
const sequelize = new Sequelize('mysql://bf3a13a7df5b2f:e2707ede@us-cdbr-iron-east-03.cleardb.net/heroku_6bdb0d8ad6c6a50?reconnect=true');
// load models
var models = [
'student',
];
models.forEach(function(model) {
module.exports[model] = sequelize.import(__dirname + '/' + model);
});
// export connection
module.exports.student= student;
module.exports.sequelize = sequelize;
student.js
var sequelize = require('./dbConnection');
var Sequelize = require('sequelize');
const student = sequelize.define('student', {
id: {
type: Sequelize.STRING,
primaryKey: true
},
name: {
type: Sequelize.STRING
},
middleName: {
type: Sequelize.STRING
},
lastName: {
type: Sequelize.STRING
},
dob: {
type: Sequelize.DATE
},
//student.sync({force: true});
});
module.exports = student;
and this is the error message I receive from the command line:
C:\Users\adria\OneDrive\Documentos\GitHub\ScholarMean1\node_modules\sequelize\lib\sequelize.js:691
this.importCache[path] = defineCall(this, DataTypes);
^
TypeError: defineCall is not a function
I managed to make it work if the model is in index.js, but because I want to make a file for each model I hope you can help me.
via Adrian Osuna
No comments:
Post a Comment