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

Commit 8eb2cf19 by Jan Aagaard Meier

bug(scope.include) Map fieldnames for include.where coming from scopes. Closes #4210

1 parent e3b9e02c
# Next
- [FIXED] Map column names with `.field` in scopes with includes. [#4210](https://github.com/sequelize/sequelize/issues/4210)
# 3.5.1 # 3.5.1
- [FIXED] Fix bug with nested includes where a middle include results in a null value which breaks $findSeperate. - [FIXED] Fix bug with nested includes where a middle include results in a null value which breaks $findSeperate.
......
...@@ -529,11 +529,9 @@ validateIncludedElement = function(include, tableNames, options) { ...@@ -529,11 +529,9 @@ validateIncludedElement = function(include, tableNames, options) {
include.attributes = Object.keys(include.model.tableAttributes); include.attributes = Object.keys(include.model.tableAttributes);
} }
include = Utils.mapOptionFieldNames(include, include.model);
// pseudo include just needed the attribute logic, return // pseudo include just needed the attribute logic, return
if (include._pseudo) { if (include._pseudo) {
return include; return Utils.mapOptionFieldNames(include, include.model);
} }
// check if the current Model is actually associated with the passed Model - or it's a pseudo include // check if the current Model is actually associated with the passed Model - or it's a pseudo include
...@@ -590,6 +588,8 @@ validateIncludedElement = function(include, tableNames, options) { ...@@ -590,6 +588,8 @@ validateIncludedElement = function(include, tableNames, options) {
Model.$injectScope(model.$scope, include); Model.$injectScope(model.$scope, include);
include = Utils.mapOptionFieldNames(include, include.model);
if (include.required === undefined) { if (include.required === undefined) {
include.required = !!include.where; include.required = !!include.where;
} }
......
...@@ -70,7 +70,12 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -70,7 +70,12 @@ describe(Support.getTestDialectTeaser('Model'), function() {
describe('scope', function () { describe('scope', function () {
beforeEach(function () { beforeEach(function () {
this.Project = this.sequelize.define('project', {}, { this.Project = this.sequelize.define('project', {
bar: {
type: Sequelize.STRING,
field: 'foo'
}
}, {
defaultScope: { defaultScope: {
where: { where: {
active: true active: true
...@@ -82,6 +87,11 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -82,6 +87,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
that: { that: {
where: { that: false }, where: { that: false },
limit: 12 limit: 12
},
foobar: {
where: {
bar: 42
}
} }
} }
}); });
...@@ -127,6 +137,15 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -127,6 +137,15 @@ describe(Support.getTestDialectTeaser('Model'), function() {
expect(options.include[0]).to.have.property('where').which.deep.equals({ this: true }); expect(options.include[0]).to.have.property('where').which.deep.equals({ this: true });
}); });
it('handles a scope with an aliased column (.field)', function () {
var options = Sequelize.Model.$validateIncludedElements({
model: this.User,
include: [{ model: this.Project.scope('foobar') }]
});
expect(options.include[0]).to.have.property('where').which.deep.equals({ foo: 42 });
});
}); });
describe('duplicating', function () { describe('duplicating', function () {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!