sequalizejs:在tableName中加点会为其添加双引号

时间:2018-10-17 00:14:12

标签: node.js postgresql sequelize.js

你在做什么?

试图使用模型从postgres表retail_lending.city_tax_reference中获取数据,但是当我在tableName中使用它时,它会在查询的表名中插入双引号

const CityTax = this.config.define('foo', {
citytaxreference_skey: Sequelize.INTEGER,
city: Sequelize.STRING,
property_tax_rate: Sequelize.NUMERIC,
minimum_property_tax: Sequelize.INTEGER,
}, {
tableName: 'retail_lending.city_tax_reference',
timestamps: false,
});

CityTax.findAll({
attributes: ['citytaxreference_skey', 'city']
}).then((project) => {
console.log(project);
});

quoteIdentifiers在建立连接期间设置为false

您期望发生什么?

_希望建模以在后台运行查询SELECT citytaxreference_skey, city FROM retail_lending.city_tax_reference AS foo 上面的查询可在postgres命令行中运行

实际上发生了什么?

模型正在使用SELECT citytaxreference_skey, city FROM "retail_lending.city_tax_reference" AS foo 上面的查询主体在postgres命令行中起作用,因为表名用引号引起来

输出:Unhandled rejection SequelizeDatabaseError: relation "retail_lending.city_tax_reference" does not exist

方言: postgres 方言版本:不确定(在线托管) 数据库版本:不确定(在线托管) 序列化版本: 4.39.0 使用最新版本进行了测试:是,4.39.0

如果有任何感谢,那么解决方案将是很好的

1 个答案:

答案 0 :(得分:3)

有一个名为schema的属性,您可以在定义这样的模型时添加

    const CityTax = this.config.define('foo', {
    citytaxreference_skey: Sequelize.INTEGER,
    city: Sequelize.STRING,
    property_tax_rate: Sequelize.NUMERIC,
    minimum_property_tax: Sequelize.INTEGER,
    }, {
    tableName: 'city_tax_reference',
    timestamps: false,
    schema:'retail_lending'
    });