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

Commit 143e0881 by Mick Hansen

Fix tests

1 parent 34fe92c6
......@@ -461,6 +461,8 @@ module.exports = (function() {
- offset -> An offset value to start from. Only useable with limit!
*/
selectQuery: function(tableName, options, factory) {
options = options || {}
var table = null
, self = this
, query
......@@ -474,7 +476,6 @@ module.exports = (function() {
, subQueryAttributes = null
, subJoinQueries = []
options = options || {}
options.table = table = !Array.isArray(tableName) ? this.quoteIdentifiers(tableName) : tableName.map(function(t) {
return this.quoteIdentifiers(t)
}.bind(this)).join(", ")
......@@ -538,12 +539,9 @@ module.exports = (function() {
return self.quoteIdentifier(as) + "." + self.quoteIdentifier(attr) + " AS " + self.quoteIdentifier(as + "." + attr)
})
if (subQuery && (include.hasIncludeRequired || include.required)) {
if (include.association.isMultiAssociation) {
mainAttributes = mainAttributes.concat(attributes)
} else {
subQueryAttributes = subQueryAttributes.concat(attributes)
}
// If not many to many, and we're doing a subquery, add attributes to the subquery
if (!include.association.isMultiAssociation && subQuery && (include.hasIncludeRequired || include.required)) {
subQueryAttributes = subQueryAttributes.concat(attributes)
} else {
mainAttributes = mainAttributes.concat(attributes)
}
......@@ -555,20 +553,7 @@ module.exports = (function() {
, throughAttributes = through.attributes.map(function(attr) {
return self.quoteIdentifier(throughAs) + "." + self.quoteIdentifier(attr) + " AS " + self.quoteIdentifier(throughAs + "." + attr)
})
if (options.includeIgnoreAttributes !== false) {
if (subQuery && (include.hasIncludeRequired || include.required)) {
if (include.association.isMultiAssociation) {
mainAttributes = mainAttributes.concat(throughAttributes)
} else {
subQueryAttributes = subQueryAttributes.concat(throughAttributes)
}
} else {
mainAttributes = mainAttributes.concat(throughAttributes)
}
}
var primaryKeysSource = Object.keys(association.source.primaryKeys)
, primaryKeysSource = Object.keys(association.source.primaryKeys)
, tableSource = parentTable
, identSource = association.identifier
, attrSource = ((!association.source.hasPrimaryKeys || primaryKeysSource.length !== 1) ? 'id' : primaryKeysSource[0])
......@@ -583,6 +568,11 @@ module.exports = (function() {
, targetJoinOn
, targetWhere
if (options.includeIgnoreAttributes !== false) {
// Through includes are always hasMany, so we need to add the attributes to the mainAttributes no matter what (Real join will never be executed in subquery)
mainAttributes = mainAttributes.concat(throughAttributes)
}
sourceJoinOn = self.quoteIdentifier(tableSource) + "." + self.quoteIdentifier(attrSource) + " = "
sourceJoinOn += self.quoteIdentifier(throughAs) + "." + self.quoteIdentifier(identSource)
......@@ -627,6 +617,8 @@ module.exports = (function() {
if (include.where) {
joinQueryItem += " AND "+self.hashToWhereConditions(includeWhere, include.daoFactory, whereOptions)
// If its a multi association we need to add a where query to the main where (executed in the subquery)
if (subQuery && association.isMultiAssociation) {
if (!options.where) options.where = {}
options.where["__"+as] = self.sequelize.asIs("(SELECT "+self.quoteIdentifier(attrRight)+" FROM " + self.quoteIdentifier(tableRight) + " WHERE " + where + " LIMIT 1) IS NOT NULL")
......@@ -660,10 +652,10 @@ module.exports = (function() {
}
if (subQuery) {
subQueryItems.push("SELECT " + subQueryAttributes.join(',') + " FROM " + options.table)
subQueryItems.push("SELECT " + subQueryAttributes.join(', ') + " FROM " + options.table)
subQueryItems.push(subJoinQueries.join(''))
} else {
mainQueryItems.push("SELECT " + mainAttributes.join(',') + " FROM " + options.table)
mainQueryItems.push("SELECT " + mainAttributes.join(', ') + " FROM " + options.table)
mainQueryItems.push(mainJoinQueries.join(''))
}
......@@ -707,7 +699,7 @@ module.exports = (function() {
}
if (subQuery) {
query = "SELECT " + mainAttributes.join(',') + " FROM ("
query = "SELECT " + mainAttributes.join(', ') + " FROM ("
query += subQueryItems.join('')
query += ") AS "+options.table
query += mainJoinQueries.join('')
......
......@@ -112,7 +112,8 @@ describe(Support.getTestDialectTeaser("Include"), function () {
{name: 'Bonanza'},
{name: 'NYSE'},
{name: 'Coshopr'}
]).done(function () {
]).done(function (err) {
if (err) return callback(err);
Company.findAll().done(callback)
})
},
......@@ -169,7 +170,8 @@ describe(Support.getTestDialectTeaser("Include"), function () {
{title: 'Bed'},
{title: 'Pen'},
{title: 'Monitor'}
]).done(function () {
]).done(function (err) {
if (err) return callback(err);
Product.findAll().done(callback)
})
},
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!