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

Commit 30bd3b08 by Mick Hansen

Only use subQueryAttributes if subQuery is indicated (required + multi)

1 parent 9a2b4e61
Showing with 4 additions and 21 deletions
......@@ -469,7 +469,7 @@ module.exports = (function() {
, mainAttributes = options.attributes
, mainJoinQueries = []
// We'll use a subquery if there's a limit, if we have hasMany associations and if any of them are filtered
, subQuery = limit && options && options.hasIncludeWhere && options.hasMultiAssociation
, subQuery = limit && options && options.hasIncludeWhere && options.hasIncludeRequired && options.hasMultiAssociation
, subQueryItems = []
, subQueryAttributes = null
, subJoinQueries = []
......@@ -538,7 +538,7 @@ module.exports = (function() {
return self.quoteIdentifier(as) + "." + self.quoteIdentifier(attr) + " AS " + self.quoteIdentifier(as + "." + attr)
})
if (limit && include.hasIncludeRequired || include.required) {
if (subQuery && include.hasIncludeRequired || include.required) {
subQueryAttributes = subQueryAttributes.concat(attributes)
} else {
mainAttributes = mainAttributes.concat(attributes)
......@@ -553,7 +553,7 @@ module.exports = (function() {
})
if (options.includeIgnoreAttributes !== false) {
if (limit && include.hasIncludeRequired || include.required) {
if (subQuery && include.hasIncludeRequired || include.required) {
subQueryAttributes = subQueryAttributes.concat(attributes)
} else {
mainAttributes = mainAttributes.concat(throughAttributes)
......@@ -617,17 +617,7 @@ module.exports = (function() {
}
}.bind(this))
}
//var conditionalJoins = ((options.hasMultiAssociation && (options.limit || options.offset)) || !options.include) && this.getConditionalJoins(options, factory),
/*if (conditionalJoins) {
query = "SELECT " + options.attributes + " FROM ( "
+ "SELECT " + options.table + ".* FROM " + options.table + this.getConditionalJoins(options, factory)
} else {*/
//query += "SELECT " + mainAttributes.join(',') + " FROM " + options.table
//query += mainJoinQueries.concat(subJoinQueries).join('')
//}
if (subQuery) {
subQueryItems.push("SELECT " + subQueryAttributes.join(',') + " FROM " + options.table)
subQueryItems.push(subJoinQueries.join(''))
......@@ -674,15 +664,8 @@ module.exports = (function() {
mainQueryItems.push(limitOrder)
}
}
//console.log(subQueryItems)
/*if (conditionalJoins) {
query += ") AS " + options.table
query += joinQuery
}*/
if (subQuery) {
//console.log(mainQueryItems)
//" + mainAttributes.join(',') + "
query = "SELECT " + mainAttributes.join(',') + " FROM ("
query += subQueryItems.join('')
query += ") AS "+options.table
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!