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

Commit 60a118f9 by Mick Hansen

Update abstract query generator so it prefixes attributes and tables with nested names

1 parent 4b31f9a8
Showing with 8 additions and 5 deletions
...@@ -383,9 +383,12 @@ module.exports = (function() { ...@@ -383,9 +383,12 @@ module.exports = (function() {
var table = include.daoFactory.tableName var table = include.daoFactory.tableName
, as = include.as , as = include.as
, joinQueryItem = "" , joinQueryItem = ""
, attributes = include.attributes.map(function(attr) { , attributes
return self.quoteIdentifier(as) + "." + self.quoteIdentifier(attr) + " AS " + self.quoteIdentifier(include.as + "." + attr)
}) if (tableName !== parentTable) as = parentTable+'.'+include.as
attributes = include.attributes.map(function(attr) {
return self.quoteIdentifier(as) + "." + self.quoteIdentifier(attr) + " AS " + self.quoteIdentifier(as + "." + attr)
})
optAttributes = optAttributes.concat(attributes) optAttributes = optAttributes.concat(attributes)
...@@ -405,9 +408,9 @@ module.exports = (function() { ...@@ -405,9 +408,9 @@ module.exports = (function() {
joinQueryItem += " LEFT OUTER JOIN " + self.quoteIdentifier(table) + " AS " + self.quoteIdentifier(as) + " ON " + self.quoteIdentifier(tableTarget) + "." + self.quoteIdentifier(attrTarget) + " = " + self.quoteIdentifier(tableJunction) + "." + self.quoteIdentifier(identTarget) joinQueryItem += " LEFT OUTER JOIN " + self.quoteIdentifier(table) + " AS " + self.quoteIdentifier(as) + " ON " + self.quoteIdentifier(tableTarget) + "." + self.quoteIdentifier(attrTarget) + " = " + self.quoteIdentifier(tableJunction) + "." + self.quoteIdentifier(identTarget)
} else { } else {
var primaryKeysLeft = ((include.association.associationType === 'BelongsTo') ? Object.keys(include.association.target.primaryKeys) : Object.keys(include.association.source.primaryKeys)) var primaryKeysLeft = ((include.association.associationType === 'BelongsTo') ? Object.keys(include.association.target.primaryKeys) : Object.keys(include.association.source.primaryKeys))
, tableLeft = ((include.association.associationType === 'BelongsTo') ? include.as : parentTable) , tableLeft = ((include.association.associationType === 'BelongsTo') ? as : parentTable)
, attrLeft = ((primaryKeysLeft.length !== 1) ? 'id' : primaryKeysLeft[0]) , attrLeft = ((primaryKeysLeft.length !== 1) ? 'id' : primaryKeysLeft[0])
, tableRight = ((include.association.associationType === 'BelongsTo') ? parentTable : include.as) , tableRight = ((include.association.associationType === 'BelongsTo') ? parentTable : as)
, attrRight = include.association.identifier , attrRight = include.association.identifier
joinQueryItem += " LEFT OUTER JOIN " + self.quoteIdentifier(table) + " AS " + self.quoteIdentifier(as) + " ON " + self.quoteIdentifier(tableLeft) + "." + self.quoteIdentifier(attrLeft) + " = " + self.quoteIdentifier(tableRight) + "." + self.quoteIdentifier(attrRight) joinQueryItem += " LEFT OUTER JOIN " + self.quoteIdentifier(table) + " AS " + self.quoteIdentifier(as) + " ON " + self.quoteIdentifier(tableLeft) + "." + self.quoteIdentifier(attrLeft) + " = " + self.quoteIdentifier(tableRight) + "." + self.quoteIdentifier(attrRight)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!