我有一个应该包含ListEntries的对象List。到目前为止,这是我的代码:
模型/ List.js
var Sequelize = require("sequelize");
module.exports=function(sequelize, DataTypes){
return List = sequelize.define("List", {
name: {
type: DataTypes.STRING
}
}, {
freezeTableName: true, // Model tableName will be the same as the model name
classMethods:{
}
})
};
模型/ ListEntry.js
var Sequelize = require("sequelize");
module.exports=function(sequelize, DataTypes){
return ListEntry = sequelize.define("ListEntry", {
entry: {
type: DataTypes.STRING
}
}, {
freezeTableName: true, // Model tableName will be the same as the model name
classMethods:{
}
})
};
模型/ index.js
var Sequelize = require("sequelize");
var sequelize = new Sequelize('development', 'root', '', {
host: 'localhost',
dialect: 'mysql',
pool: {
max: 5,
min: 0,
idle: 10000
}
});
var models = [
'List', 'ListEntry'
];
models.forEach(function(model) {
module.exports[model] = sequelize.import(__dirname + '/../models/' + model);
});
var List = require('../models/').List;
var ListEntry = require('../models/').ListEntry;
List.hasMany(ListEntry, {as: 'Notes'});
List.sync()
ListEntry.sync()
但如果我现在想从控制器中获取List中的所有ListEntries,我会收到错误:
router.get('/', function (req, res, next) {
List.getNotes().then(function(bla){
});
});
List.getNotes is not a function