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

Commit 027d914e by Mick Hansen

better (and worse code) quote table logic

1 parent 64fb3354
......@@ -945,6 +945,8 @@ module.exports = (function() {
, where = {}
, self = this
options = options || {}
if (typeof prepend === 'undefined') {
prepend = true
}
......@@ -959,7 +961,8 @@ module.exports = (function() {
result = "(" + result + ")"
} else if (Utils.isHash(smth)) {
if (prepend) {
smth = Utils.prependTableNameToHash(tableName, smth, self.quoteIdentifier.bind(self))
options.keysEscaped = true
smth = this.prependTableNameToHash(tableName, smth)
}
result = this.hashToWhereConditions(smth, factory, options)
} else if (typeof smth === 'number') {
......@@ -973,7 +976,9 @@ module.exports = (function() {
}
where[primaryKeys] = smth
smth = Utils.prependTableNameToHash(tableName, where)
options.keysEscaped = true
smth = this.prependTableNameToHash(tableName, where)
result = this.hashToWhereConditions(smth)
} else if (typeof smth === "string") {
result = smth
......@@ -999,6 +1004,30 @@ module.exports = (function() {
return result ? result : '1=1'
},
prependTableNameToHash: function(tableName, hash) {
if (tableName) {
var _hash = {}
for (var key in hash) {
if (key instanceof Utils.literal) {
_hash[key] = hash[key]
} else if (key.indexOf('.') === -1) {
if (tableName instanceof Utils.literal) {
_hash[tableName + '.' + this.quoteIdentifier(key)] = hash[key]
} else {
_hash[this.quoteTable(tableName) + '.' + this.quoteIdentifier(key)] = hash[key]
}
} else {
_hash[this.quoteIdentifiers(key)] = hash[key]
}
}
return _hash
} else {
return hash
}
},
findAssociation: function(attribute, dao){
var associationToReturn;
......
......@@ -445,30 +445,6 @@ var Utils = module.exports = {
return result
},
prependTableNameToHash: function(tableName, hash, quote) {
if (tableName) {
var _hash = {}
for (var key in hash) {
if (key instanceof Utils.literal) {
_hash[key] = hash[key]
} else if (key.indexOf('.') === -1) {
if (tableName instanceof Utils.literal) {
_hash[tableName + '.' + quote(key)] = hash[key]
} else {
_hash[tableName + '.' + key] = hash[key]
}
} else {
_hash[key] = hash[key]
}
}
return _hash
} else {
return hash
}
},
firstValueOfHash: function(obj) {
for (var key in obj) {
if (obj.hasOwnProperty(key))
......
......@@ -76,7 +76,7 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
})
})
it.only('supports schemas', function (done) {
it('supports schemas', function (done) {
var User = this.sequelize.define('UserXYZ', { username: Sequelize.STRING, gender: Sequelize.STRING }).schema('archive')
, Task = this.sequelize.define('TaskXYZ', { title: Sequelize.STRING, status: Sequelize.STRING }).schema('archive')
, self = this
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!