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

Commit f23cdeb0 by José Moreira

Fix bug (cause by required on N:M)

1 parent 5ef9edc4
Showing with 11 additions and 10 deletions
...@@ -737,25 +737,26 @@ module.exports = (function() { ...@@ -737,25 +737,26 @@ module.exports = (function() {
joinQueryItem += sourceJoinOn joinQueryItem += sourceJoinOn
// Generate join SQL for right side of through // Generate join SQL for right side of through
joinQueryItem += joinType + self.quoteTable(table, as) + " ON " joinQueryItem += joinType + self.quoteTable( table, as ) + " ON "
joinQueryItem += targetJoinOn joinQueryItem += targetJoinOn
if (include.where) { if ( include.where ) {
targetWhere = self.getWhereConditions(include.where, self.sequelize.literal(self.quoteIdentifier(as)), include.daoFactory, whereOptions) targetWhere = self.getWhereConditions(include.where, self.sequelize.literal(self.quoteIdentifier(as)), include.daoFactory, whereOptions)
joinQueryItem += " AND "+ targetWhere joinQueryItem += " AND "+ targetWhere
if (subQuery) { if (subQuery) {
if (!options.where) options.where = {} if (!options.where) options.where = {}
// Creating the as-is where for the subQuery, checks that the required association exists // Creating the as-is where for the subQuery, checks that the required association exists
var _where = "("; options.where["__"+throughAs] = self.sequelize.asIs([ '(',
_where += "SELECT "+self.quoteIdentifier(identSource)+" FROM " + self.quoteTable(throughTable, throughAs);
_where += joinType + self.quoteTable(table, as) + " ON "+targetJoinOn; "SELECT " + self.quoteIdentifier( throughAs ) + "." + self.quoteIdentifier( identSource ) + " FROM " + self.quoteTable(throughTable, throughAs),
_where += " WHERE " + sourceJoinOn + " AND " + targetWhere + " LIMIT 1" ! include.required && joinType + self.quoteTable( association.source.tableName, tableSource ) + " ON " + sourceJoinOn || '',
_where += ")"; joinType + self.quoteTable( table, as ) + " ON " + targetJoinOn,
_where += " IS NOT NULL" "WHERE " + ( ! include.required && targetWhere || sourceJoinOn + " AND " + targetWhere ),
"LIMIT 1",
options.where["__"+throughAs] = self.sequelize.asIs(_where)
')', 'IS NOT NULL'].join(' '))
} }
} }
} else { } else {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!