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

Commit 630b3c1a by Lemon

Many-many association eager loading support for MySQL

1 parent 6d48ef77
Showing with 14 additions and 1 deletions
...@@ -187,6 +187,7 @@ module.exports = (function() { ...@@ -187,6 +187,7 @@ module.exports = (function() {
optAttributes = optAttributes.concat(attributes) optAttributes = optAttributes.concat(attributes)
if (include.association.associationType !== 'HasMany') {
var table = include.daoFactory.tableName var table = include.daoFactory.tableName
var as = include.as var as = include.as
var tableLeft = ((include.association.associationType === 'BelongsTo') ? include.as : tableName) var tableLeft = ((include.association.associationType === 'BelongsTo') ? include.as : tableName)
...@@ -194,7 +195,19 @@ module.exports = (function() { ...@@ -194,7 +195,19 @@ module.exports = (function() {
var tableRight = ((include.association.associationType === 'BelongsTo') ? tableName : include.as) var tableRight = ((include.association.associationType === 'BelongsTo') ? tableName : include.as)
var attrRight = include.association.identifier var attrRight = include.association.identifier
joinQuery += " LEFT OUTER JOIN " + this.quoteIdentifier(table) + " AS " + this.quoteIdentifier(as) + " ON " + this.quoteIdentifier(tableLeft) + "." + this.quoteIdentifier(attrLeft) + " = " + this.quoteIdentifier(tableRight) + "." + this.quoteIdentifier(attrRight) joinQuery += " LEFT OUTER JOIN " + this.quoteIdentifier(table) + " AS " + this.quoteIdentifier(as) + " ON " + this.quoteIdentifier(tableLeft) + "." + this.quoteIdentifier(attrLeft) + " = " + this.quoteIdentifier(tableRight) + "." + this.quoteIdentifier(attrRight)
} else {
var table = include.daoFactory.tableName
var as = include.as
var tableLeft = tableName
var identLeft = include.association.identifier
var attrLeft = 'id'
var tableRight = include.as
var identRight = include.association.foreignIdentifier
var attrRight = 'id'
var tableJunction = include.association.connectorDAO.tableName
joinQuery += " LEFT OUTER JOIN " + this.quoteIdentifier(tableJunction) + " ON " + this.quoteIdentifier(tableLeft) + "." + this.quoteIdentifier(attrLeft) + " = " + this.quoteIdentifier(tableJunction) + "." + this.quoteIdentifier(identLeft)
joinQuery += " LEFT OUTER JOIN " + this.quoteIdentifier(table) + " AS " + this.quoteIdentifier(as) + " ON " + this.quoteIdentifier(tableRight) + "." + this.quoteIdentifier(attrRight) + " = " + this.quoteIdentifier(tableJunction) + "." + this.quoteIdentifier(identRight)
}
}.bind(this)) }.bind(this))
options.attributes = optAttributes.join(', ') options.attributes = optAttributes.join(', ')
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!