node.js - sequelize查询语句时转成的MYSQL语句中表名并不是自己定义的?
PHP中文网
PHP中文网 2017-04-17 16:08:03
0
1
485

我在查询数据库时,定义的模板是:

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中文网
PHP中文网

认证0级讲师

Antworte allen(1)
洪涛

其实定义的模型里面可以设置真正的表名的,sequelize.define的第三个参数是一个json对象,可以在里面设置tableName,具体用法请参考sequelize官方文档

Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage