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

Commit add75a67 by Mick Hansen

cleanup

1 parent 6f882422
Showing with 14 additions and 14 deletions
......@@ -526,7 +526,7 @@ module.exports = (function() {
- 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
options = options || {}
......@@ -550,7 +550,7 @@ module.exports = (function() {
}.bind(this)).join(", ")
if (subQuery && mainAttributes) {
mainAttributes = mainAttributes.concat(factory.hasPrimaryKeys ? factory.primaryKeyAttributes : ['id'])
mainAttributes = mainAttributes.concat(Model.primaryKeyAttributes)
}
// Escape attributes
......@@ -630,16 +630,16 @@ module.exports = (function() {
, throughAttributes = through.attributes.map(function(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
, identSource = association.identifier
, attrSource = ((!association.source.hasPrimaryKeys || primaryKeysSource.length !== 1) ? 'id' : primaryKeysSource[0])
, attrSource = primaryKeysSource[0]
, where
, primaryKeysTarget = Object.keys(association.target.primaryKeys)
, primaryKeysTarget = association.target.primaryKeyAttributes
, tableTarget = as
, identTarget = association.foreignIdentifier
, attrTarget = ((!include.association.target.hasPrimaryKeys || primaryKeysTarget.length !== 1) ? 'id' : primaryKeysTarget[0])
, attrTarget = primaryKeysTarget[0]
, sourceJoinOn
, targetJoinOn
......@@ -687,10 +687,10 @@ module.exports = (function() {
}
}
} else {
var primaryKeysLeft = ((association.associationType === 'BelongsTo') ? Object.keys(association.target.primaryKeys) : Object.keys(include.association.source.primaryKeys))
, tableLeft = ((association.associationType === 'BelongsTo') ? as : parentTable)
, attrLeft = ((primaryKeysLeft.length !== 1) ? 'id' : primaryKeysLeft[0])
, tableRight = ((association.associationType === 'BelongsTo') ? parentTable : as)
var primaryKeysLeft = association.associationType === 'BelongsTo' ? association.target.primaryKeyAttributes : include.association.source.primaryKeyAttributes
, tableLeft = association.associationType === 'BelongsTo' ? as : parentTable
, attrLeft = primaryKeysLeft[0]
, tableRight = association.associationType === 'BelongsTo' ? parentTable : as
, attrRight = association.identifier
, where
......@@ -751,7 +751,7 @@ module.exports = (function() {
// Add WHERE to sub or main query
if (options.hasOwnProperty('where')) {
options.where = this.getWhereConditions(options.where, tableName, factory, options)
options.where = this.getWhereConditions(options.where, tableName, Model, options)
if (subQuery) {
subQueryItems.push(" WHERE " + options.where)
} else {
......@@ -761,7 +761,7 @@ module.exports = (function() {
// Add GROUP BY to sub or main query
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) {
subQueryItems.push(" GROUP BY " + options.group)
} else {
......@@ -771,7 +771,7 @@ module.exports = (function() {
// Add HAVING to sub or main query
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) {
subQueryItems.push(" HAVING " + options.having)
} else {
......@@ -781,7 +781,7 @@ module.exports = (function() {
// Add ORDER to sub or main query
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) {
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!