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

Commit bf36239a by ThePoloQ

Update query-generator.js

1 parent 1d104c1d
Showing with 37 additions and 6 deletions
...@@ -407,6 +407,38 @@ module.exports = (function() { ...@@ -407,6 +407,38 @@ module.exports = (function() {
} }
}, },
getTableNameOrder: function (obj){
if (Utils._.isString(obj)) {
return obj
} else if (Array.isArray(obj)) {
return this.getTableNameOrder(obj[0])
} else if (obj instanceof Utils.fn) {
return this.getTableNameOrder(obj.args)
} else if (obj instanceof Utils.col) {
return obj.col.split('.')[0]
} else if ('raw' in obj){
return obj.raw
} else{
return ''
}
},
getSpecificQuoteOrder: function (obj){
if (Utils._.isString(obj)) {
return this.quoteIdentifier(obj)
} else if (Array.isArray(obj)) {
return this.getSpecificQuoteOrder(obj[0]) + (obj.length > 1 ? ' ' + obj[1] : '')
} else if (obj instanceof Utils.fn) {
return obj.fn + '(' + this.getSpecificQuoteOrder(obj.args) + ')'
} else if (obj instanceof Utils.col) {
return this.quoteIdentifier(obj.col)
} else if ('raw' in obj){
return obj.raw
} else{
return ''
}
},
/* /*
Create a trigger Create a trigger
*/ */
...@@ -802,16 +834,15 @@ module.exports = (function() { ...@@ -802,16 +834,15 @@ module.exports = (function() {
if (Array.isArray(options.order)) { if (Array.isArray(options.order)) {
options.order.forEach(function (t) { options.order.forEach(function (t) {
var strOrder = this.quote(t, factory) var strOrder = this.quote(t, factory)
var asName = strOrder.match(/`(.*)`\./) var tableName = this.getTableNameOrder(t)
if (subQuery && !(t[0] instanceof daoFactory) && !(t[0].model instanceof daoFactory)) { if (subQuery && !(t[0] instanceof daoFactory) && !(t[0].model instanceof daoFactory)) {
if(asName && subQueryAs.indexOf(asName[1]) > -1){ if(tableName && subQueryAs.indexOf(tableName) > -1){
subQueryOrder.push(strOrder) subQueryOrder.push(strOrder)
} }
} }
if(subQuery && asName && asName[1] != subQueryAs[0] && subQueryAs.indexOf(asName[1]) > -1){ if(subQuery && tableName !== subQueryAs[0] && subQueryAs.indexOf(tableName) > -1){
mainQueryOrder.push(strOrder.replace(/`\.`/,'.')) mainQueryOrder.push(this.getSpecificQuoteOrder(t))
}else{ }else{
mainQueryOrder.push(strOrder) mainQueryOrder.push(strOrder)
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!