如何调用函数(search_all_user)进行导出(node.js / sequelize)
module.exports = function (sequelize, Sequelize, DataTypes) {
var User = sequelize.define('user', {
id: {type: Sequelize.INTEGER, unique: true, primaryKey: true, autoIncrement: true},
username: {type: Sequelize.STRING(32), unique: true, allowNull: false},
}, {
classMethods: {
search_all_user: function() {
User.findOne({where: {username: 'coderock'}}).then(function(user){
console.log(user.username);
});
}
}
});
return User;
};
控制器:
model = require('./../models/user.js');
exports.index = function (request, response, next) {
// how to insert function () search_all_user?
response.render('user_signup', {title: 'Регистрация пользователя'});
};
答案 0 :(得分:0)
search_all_users
。因此,您可以在需要模型后在控制器中调用它。这是一个例子:
var model = require('./../models/user.js');
exports.index = function (request, response, next) {
model.search_all_users.then(...);
};