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

Commit 7487701a by Jan Aagaard Meier

fixed(scopes/include) Fix scopes in conjunction with include all. Closes #4584

1 parent 31089c7d
......@@ -7,6 +7,7 @@
+ mysql@2.9.0
- coffee-script
- [FIXED] Add limit to `findOne` when using queries like `{ id: { $gt ...` [#4416](https://github.com/sequelize/sequelize/issues/4416)
- [FIXED] Include all with scopes [#4584](https://github.com/sequelize/sequelize/issues/4584)
# 3.10.0
- [ADDED] support `search_path` for postgres with lots of schemas [#4534](https://github.com/sequelize/sequelize/pull/4534)
......
......@@ -2576,8 +2576,8 @@ Model.$injectScope = function (scope, options) {
// Reverse so we consider the latest include first.
// This is used if several scopes specify the same include - the last scope should take precendence
scope.include.reverse().forEach(function (scopeInclude) {
if (!_.any(options.include, function matchesModelAndAlias(item) {
var sameModel = item.model.name === scopeInclude.model.name;
if (scopeInclude.all || !_.any(options.include, function matchesModelAndAlias(item) {
var sameModel = item.model && item.model.name === scopeInclude.model.name;
if (sameModel && item.as) {
return item.as === scopeInclude.as;
......
......@@ -315,5 +315,48 @@ describe(Support.getTestDialectTeaser('Model'), function() {
expect(options.include[0]).to.deep.equal({ model: User, where: { something: true }});
expect(options.include[1]).to.deep.equal({ model: Project, where: { something: false }});
});
describe('include all', function () {
it('scope with all', function () {
var scope = {
include: [
{ all: true }
]
};
var options = {
include: [
{ model: User, where: { something: true }}
]
};
current.Model.$injectScope(scope, options);
expect(options.include).to.have.length(2);
expect(options.include[0]).to.deep.equal({ model: User, where: { something: true }});
expect(options.include[1]).to.deep.equal({ all: true });
});
it('options with all', function () {
var scope = {
include: [
{ model: User, where: { something: true }}
]
};
var options = {
include: [
{ all: true }
]
};
current.Model.$injectScope(scope, options);
expect(options.include).to.have.length(2);
expect(options.include[0]).to.deep.equal({ all: true });
expect(options.include[1]).to.deep.equal({ model: User, where: { something: true }});
});
});
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!