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

Commit 57ecd46c by overlookmotel

Separate expanding include all into own function

1 parent ecf511ae
Showing with 28 additions and 12 deletions
......@@ -698,6 +698,7 @@ module.exports = (function() {
if (options.include) {
hasJoin = true;
expandIncludeAll.call(this, options);
validateIncludedElements.call(this, options, tableNames);
if (options.attributes) {
......@@ -824,6 +825,7 @@ module.exports = (function() {
var col = '*';
if (options.include) {
col = this.name + '.' + this.primaryKeyAttribute;
expandIncludeAll.call(this, options);
validateIncludedElements.call(this, options);
}
......@@ -940,6 +942,7 @@ module.exports = (function() {
if (!options.includeValidated) {
conformOptions(options);
if (options.include) {
expandIncludeAll.call(this, options);
validateIncludedElements.call(this, options);
}
}
......@@ -954,6 +957,7 @@ module.exports = (function() {
if (!options.includeValidated) {
conformOptions(options);
if (options.include) {
expandIncludeAll.call(this, options);
validateIncludedElements.call(this, options);
}
}
......@@ -1756,17 +1760,7 @@ module.exports = (function() {
// validate all included elements
var includes = options.include;
for (var index = 0; index < includes.length; index++) {
var include = includes[index];
if (include.all) {
includes.splice(index, 1);
index--;
validateIncludedAllElement.call(this, includes, include);
continue;
}
include = includes[index] = validateIncludedElement.call(this, include, tableNames);
var include = includes[index] = validateIncludedElement.call(this, includes[index], tableNames);
include.parent = options;
// associations that are required or have a required child as is not a ?:M association are candidates for the subquery
......@@ -1867,7 +1861,29 @@ module.exports = (function() {
}
};
var validateIncludedAllElement = function(includes, include) {
var expandIncludeAll = function(options) {
var includes = options.include;
if (!includes) {
return;
}
for (var index = 0; index < includes.length; index++) {
var include = includes[index];
if (include.all) {
includes.splice(index, 1);
index--;
expandIncludeAllElement.call(this, includes, include);
}
}
Utils._.forEach(includes, function(include) {
expandIncludeAll.call(include.model, include);
});
};
var expandIncludeAllElement = function(includes, include) {
// check 'all' attribute provided is valid
var all = include.all;
delete include.all;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!