我在查询数据库时,定义的模板是:
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是怎么来的?
PHP中文网2017-04-17 16:10:03
其實定義的模型裡面可以設定真正的表名的,sequelize.define的第三個參數是一個json對象,可以在裡面設置tableName,具體用法請參考sequelize官方文檔