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

Commit add75a67 by Mick Hansen

cleanup

1 parent 6f882422
Showing with 14 additions and 14 deletions
...@@ -526,7 +526,7 @@ module.exports = (function() { ...@@ -526,7 +526,7 @@ module.exports = (function() {
- offset -> An offset value to start from. Only useable with limit! - offset -> An offset value to start from. Only useable with limit!
*/ */
selectQuery: function(tableName, options, factory) { selectQuery: function(tableName, options, Model) {
// Enter and change at your own peril -- Mick Hansen // Enter and change at your own peril -- Mick Hansen
options = options || {} options = options || {}
...@@ -550,7 +550,7 @@ module.exports = (function() { ...@@ -550,7 +550,7 @@ module.exports = (function() {
}.bind(this)).join(", ") }.bind(this)).join(", ")
if (subQuery && mainAttributes) { if (subQuery && mainAttributes) {
mainAttributes = mainAttributes.concat(factory.hasPrimaryKeys ? factory.primaryKeyAttributes : ['id']) mainAttributes = mainAttributes.concat(Model.primaryKeyAttributes)
} }
// Escape attributes // Escape attributes
...@@ -630,16 +630,16 @@ module.exports = (function() { ...@@ -630,16 +630,16 @@ module.exports = (function() {
, throughAttributes = through.attributes.map(function(attr) { , throughAttributes = through.attributes.map(function(attr) {
return self.quoteIdentifier(throughAs) + "." + self.quoteIdentifier(attr) + " AS " + self.quoteIdentifier(throughAs + "." + attr) return self.quoteIdentifier(throughAs) + "." + self.quoteIdentifier(attr) + " AS " + self.quoteIdentifier(throughAs + "." + attr)
}) })
, primaryKeysSource = Object.keys(association.source.primaryKeys) , primaryKeysSource = association.source.primaryKeyAttributes
, tableSource = parentTable , tableSource = parentTable
, identSource = association.identifier , identSource = association.identifier
, attrSource = ((!association.source.hasPrimaryKeys || primaryKeysSource.length !== 1) ? 'id' : primaryKeysSource[0]) , attrSource = primaryKeysSource[0]
, where , where
, primaryKeysTarget = Object.keys(association.target.primaryKeys) , primaryKeysTarget = association.target.primaryKeyAttributes
, tableTarget = as , tableTarget = as
, identTarget = association.foreignIdentifier , identTarget = association.foreignIdentifier
, attrTarget = ((!include.association.target.hasPrimaryKeys || primaryKeysTarget.length !== 1) ? 'id' : primaryKeysTarget[0]) , attrTarget = primaryKeysTarget[0]
, sourceJoinOn , sourceJoinOn
, targetJoinOn , targetJoinOn
...@@ -687,10 +687,10 @@ module.exports = (function() { ...@@ -687,10 +687,10 @@ module.exports = (function() {
} }
} }
} else { } else {
var primaryKeysLeft = ((association.associationType === 'BelongsTo') ? Object.keys(association.target.primaryKeys) : Object.keys(include.association.source.primaryKeys)) var primaryKeysLeft = association.associationType === 'BelongsTo' ? association.target.primaryKeyAttributes : include.association.source.primaryKeyAttributes
, tableLeft = ((association.associationType === 'BelongsTo') ? as : parentTable) , tableLeft = association.associationType === 'BelongsTo' ? as : parentTable
, attrLeft = ((primaryKeysLeft.length !== 1) ? 'id' : primaryKeysLeft[0]) , attrLeft = primaryKeysLeft[0]
, tableRight = ((association.associationType === 'BelongsTo') ? parentTable : as) , tableRight = association.associationType === 'BelongsTo' ? parentTable : as
, attrRight = association.identifier , attrRight = association.identifier
, where , where
...@@ -751,7 +751,7 @@ module.exports = (function() { ...@@ -751,7 +751,7 @@ module.exports = (function() {
// Add WHERE to sub or main query // Add WHERE to sub or main query
if (options.hasOwnProperty('where')) { if (options.hasOwnProperty('where')) {
options.where = this.getWhereConditions(options.where, tableName, factory, options) options.where = this.getWhereConditions(options.where, tableName, Model, options)
if (subQuery) { if (subQuery) {
subQueryItems.push(" WHERE " + options.where) subQueryItems.push(" WHERE " + options.where)
} else { } else {
...@@ -761,7 +761,7 @@ module.exports = (function() { ...@@ -761,7 +761,7 @@ module.exports = (function() {
// Add GROUP BY to sub or main query // Add GROUP BY to sub or main query
if (options.group) { if (options.group) {
options.group = Array.isArray(options.group) ? options.group.map(function (t) { return this.quote(t, factory) }.bind(this)).join(', ') : options.group options.group = Array.isArray(options.group) ? options.group.map(function (t) { return this.quote(t, Model) }.bind(this)).join(', ') : options.group
if (subQuery) { if (subQuery) {
subQueryItems.push(" GROUP BY " + options.group) subQueryItems.push(" GROUP BY " + options.group)
} else { } else {
...@@ -771,7 +771,7 @@ module.exports = (function() { ...@@ -771,7 +771,7 @@ module.exports = (function() {
// Add HAVING to sub or main query // Add HAVING to sub or main query
if (options.hasOwnProperty('having')) { if (options.hasOwnProperty('having')) {
options.having = this.getWhereConditions(options.having, tableName, factory, options, false) options.having = this.getWhereConditions(options.having, tableName, Model, options, false)
if (subQuery) { if (subQuery) {
subQueryItems.push(" HAVING " + options.having) subQueryItems.push(" HAVING " + options.having)
} else { } else {
...@@ -781,7 +781,7 @@ module.exports = (function() { ...@@ -781,7 +781,7 @@ module.exports = (function() {
// Add ORDER to sub or main query // Add ORDER to sub or main query
if (options.order) { if (options.order) {
options.order = Array.isArray(options.order) ? options.order.map(function (t) { return this.quote(t, factory) }.bind(this)).join(', ') : options.order options.order = Array.isArray(options.order) ? options.order.map(function (t) { return this.quote(t, Model) }.bind(this)).join(', ') : options.order
if (subQuery) { if (subQuery) {
subQueryItems.push(" ORDER BY " + options.order) subQueryItems.push(" ORDER BY " + options.order)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!