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

Commit e07a7bea by Simon Schick Committed by Erik Seliger

fix(query-generator): correctly treat projection inversion in include default scope (#10597)

Fixes #10399
1 parent db16cd56
...@@ -1425,6 +1425,7 @@ class QueryGenerator { ...@@ -1425,6 +1425,7 @@ class QueryGenerator {
// includeIgnoreAttributes is used by aggregate functions // includeIgnoreAttributes is used by aggregate functions
if (topLevelInfo.options.includeIgnoreAttributes !== false) { if (topLevelInfo.options.includeIgnoreAttributes !== false) {
include.model._expandAttributes(include);
const includeAttributes = include.attributes.map(attr => { const includeAttributes = include.attributes.map(attr => {
let attrAs = attr; let attrAs = attr;
let verbatim = false; let verbatim = false;
......
...@@ -3082,7 +3082,9 @@ class Model { ...@@ -3082,7 +3082,9 @@ class Model {
} }
static _expandAttributes(options) { static _expandAttributes(options) {
if (_.isPlainObject(options.attributes)) { if (!_.isPlainObject(options.attributes)) {
return;
}
let attributes = Object.keys(this.rawAttributes); let attributes = Object.keys(this.rawAttributes);
if (options.attributes.exclude) { if (options.attributes.exclude) {
...@@ -3095,7 +3097,6 @@ class Model { ...@@ -3095,7 +3097,6 @@ class Model {
options.attributes = attributes; options.attributes = attributes;
} }
}
// Inject _scope into options. // Inject _scope into options.
static _injectScope(options) { static _injectScope(options) {
......
...@@ -46,6 +46,18 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -46,6 +46,18 @@ describe(Support.getTestDialectTeaser('Model'), () => {
} }
}); });
this.DefaultScopeExclude = this.sequelize.define('DefaultScopeExclude', {
name: Sequelize.STRING
}, {
defaultScope: {
attributes: {
exclude: ['name']
}
}
});
this.ScopeMe.hasMany(this.DefaultScopeExclude);
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
const records = [ const records = [
{ username: 'tony', email: 'tony@sequelizejs.com', access_level: 3, other_value: 7, parent_id: 1 }, { username: 'tony', email: 'tony@sequelizejs.com', access_level: 3, other_value: 7, parent_id: 1 },
...@@ -119,5 +131,11 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -119,5 +131,11 @@ describe(Support.getTestDialectTeaser('Model'), () => {
expect(user.username).to.equal('fake'); expect(user.username).to.equal('fake');
}); });
}); });
it('should work when included with default scope', function() {
return this.ScopeMe.findOne({
include: [this.DefaultScopeExclude]
});
});
}); });
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!