sequelize.query()返回两次相同的结果 [英] sequelize.query() returns same result twice
问题描述
我正在使用sequelize
连接mysql数据库的nodejs项目中工作.我还使用 sequelize-values 从Sequelize实例获取原始数据.
I am working in nodejs project in that using sequelize
for connecting mysql database. I am also using sequelize-values for getting raw data from Sequelize instances.
我写了下面的代码
var Sequelize = require('sequelize');
require('sequelize-values')(Sequelize);
var sequelizeObj = new Sequelize('mysql://root:@localhost/database');
sequelizeObj.authenticate().then(function (errors) {
console.log(errors)
});
sequelizeObj.query("SELECT * FROM `reports` WHERE `id` = 1200").then(function (result) {
});
现在表reports
仅具有id
1200的1条记录,但是result
为相同记录提供了两个对象,这意味着两个记录的ID均为1200.
Now the table reports
have only 1 record for id
1200, But the result
gives two objects for same records, Means both records are same of id 1200.
[ [ { id: 1200,
productivity_id: 9969,
gross_percentage_points: 100 } ],
[ { id: 1200,
productivity_id: 9969,
gross_percentage_points: 100 } ] ]
让我知道我在做什么错吗?
Let me know what I am doing wrong?
推荐答案
第一个对象是结果对象,第二个是元数据对象(包含受影响的行等)-但是在mysql中,这两个对象是相等的.
The first object is the result object, the second is the metadata object (containing affected rows etc) - but in mysql, those two are equal.
将{ type: Sequelize.QueryTypes.SELECT }
作为第二个参数传递将给您一个结果对象(省略了元数据对象
Passing { type: Sequelize.QueryTypes.SELECT }
as the second argument will give you a single result object (metadata object omitted
https://github.com/sequelize/sequelize/wiki/Upgradeing-to-2.0#changes-to-raw-query
这篇关于sequelize.query()返回两次相同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!