问题描述
我在查询数据库时,定义的模板是:
module.exports = function(sequelize,Sequelize){
var User = sequelize.define(’userinfo’,{ id:{type: Sequelize.FLOAT,primaryKey: true }, name:{type:Sequelize.STRING } , password :{type: Sequelize.STRING }, email :{type: Sequelize.STRING } , phone :{type: Sequelize.STRING }, qq :{type: Sequelize.STRING }, ifmanager:{type: Sequelize.BOOLEAN }});return User;
}
然后进行调用:var User = require(’./module/userinfo’)(sequelize,Sequelize);
var result = yield User.findAll({ attributes:[’password’], where:{name:name }});console.log(result);
但最终控制台打印出的MYSQL语句是SELECT password FROM userinfos AS userinfos WHERE userinfos.name = ’jession’请问userinfos是怎么来的?
问题解答
回答1:其实定义的模型里面可以设置真正的表名的,sequelize.define的第三个参数是一个json对象,可以在里面设置tableName,具体用法请参考sequelize官方文档