不要怂,就是干,撸起袖子干!

Commit 7a90df5c by George Maddocks Committed by Sushant

fix(query): do not omit field when same field/name in fieldMap (#11492)

1 parent c7138f5a
...@@ -248,7 +248,7 @@ class AbstractQuery { ...@@ -248,7 +248,7 @@ class AbstractQuery {
if (this.options.fieldMap) { if (this.options.fieldMap) {
const fieldMap = this.options.fieldMap; const fieldMap = this.options.fieldMap;
results = results.map(result => _.reduce(fieldMap, (result, name, field) => { results = results.map(result => _.reduce(fieldMap, (result, name, field) => {
if (result[field] !== undefined) { if (result[field] !== undefined && name !== field) {
result[name] = result[field]; result[name] = result[field];
delete result[field]; delete result[field];
} }
......
...@@ -468,6 +468,18 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => { ...@@ -468,6 +468,18 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
}); });
}); });
it('keeps field names that are mapped to the same name', function() {
return this.sequelize.query(this.insertQuery).then(() => {
return this.sequelize.query(`SELECT * FROM ${qq(this.User.tableName)};`, {
type: 'SELECT',
fieldMap: { username: 'username', email_address: 'email' }
});
}).then(users => {
expect(users[0].username).to.be.equal('john');
expect(users[0].email).to.be.equal('john@gmail.com');
});
});
it('reject if `values` and `options.replacements` are both passed', function() { it('reject if `values` and `options.replacements` are both passed', function() {
return this.sequelize.query({ query: 'select ? as foo, ? as bar', values: [1, 2] }, { raw: true, replacements: [1, 2] }) return this.sequelize.query({ query: 'select ? as foo, ? as bar', values: [1, 2] }, { raw: true, replacements: [1, 2] })
.should.be.rejectedWith(Error, 'Both `sql.values` and `options.replacements` cannot be set at the same time'); .should.be.rejectedWith(Error, 'Both `sql.values` and `options.replacements` cannot be set at the same time');
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!