search

Home  >  Q&A  >  body text

node.js - sequelize查询语句时转成的MYSQL语句中表名并不是自己定义的?

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

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中文网2786 days ago490

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 16:10:03

    In fact, the real table name can be set in the defined model. The third parameter of sequelize.define is a json object, in which the tableName can be set. For specific usage, please refer to the official sequelize documentation

    reply
    0
  • Cancelreply