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

Commit 7287f332 by Daniel Durante

Added the ability to update records without a primary key but used a where optio…

…n when selecting with updateAttribute
1 parent 5fa778ea
Showing with 17 additions and 3 deletions
...@@ -15,7 +15,8 @@ module.exports = (function() { ...@@ -15,7 +15,8 @@ module.exports = (function() {
freezeTableName: false, freezeTableName: false,
underscored: false, underscored: false,
syncOnAssociation: true, syncOnAssociation: true,
paranoid: false paranoid: false,
whereCollection: null
}, options || {}) }, options || {})
this.name = name this.name = name
...@@ -153,6 +154,9 @@ module.exports = (function() { ...@@ -153,6 +154,9 @@ module.exports = (function() {
}.bind(this)) }.bind(this))
} }
// whereCollection is used for non-primary key updates
this.options.whereCollection = optcpy.where || undefined;
return this.QueryInterface.select(this, this.tableName, options, { type: 'SELECT', hasJoin: hasJoin }) return this.QueryInterface.select(this, this.tableName, options, { type: 'SELECT', hasJoin: hasJoin })
} }
...@@ -161,6 +165,9 @@ module.exports = (function() { ...@@ -161,6 +165,9 @@ module.exports = (function() {
var optcpy = Utils._.clone(options) var optcpy = Utils._.clone(options)
optcpy.attributes = optcpy.attributes || [Utils.addTicks(this.tableName)+".*"] optcpy.attributes = optcpy.attributes || [Utils.addTicks(this.tableName)+".*"]
// whereCollection is used for non-primary key updates
this.options.whereCollection = optcpy.where || undefined;
return this.QueryInterface.select(this, [this.tableName, joinTableName], optcpy, { type: 'SELECT' }) return this.QueryInterface.select(this, [this.tableName, joinTableName], optcpy, { type: 'SELECT' })
} }
...@@ -215,6 +222,9 @@ module.exports = (function() { ...@@ -215,6 +222,9 @@ module.exports = (function() {
options.limit = 1 options.limit = 1
// whereCollection is used for non-primary key updates
this.options.whereCollection = optcpy.where || undefined;
return this.QueryInterface.select(this, this.tableName, options, { plain: true, type: 'SELECT', hasJoin: hasJoin }) return this.QueryInterface.select(this, this.tableName, options, { plain: true, type: 'SELECT', hasJoin: hasJoin })
} }
......
...@@ -121,8 +121,12 @@ module.exports = (function() { ...@@ -121,8 +121,12 @@ module.exports = (function() {
if(this.isNewRecord) { if(this.isNewRecord) {
return this.QueryInterface.insert(this, this.__factory.tableName, values) return this.QueryInterface.insert(this, this.__factory.tableName, values)
} else { } else {
var identifier = this.__options.hasPrimaryKeys ? this.primaryKeyValues : this.id var identifier = this.__options.hasPrimaryKeys ? this.primaryKeyValues : this.id;
, tableName = this.__factory.tableName
if (identifier === null && this.__options.whereCollection !== null)
identifier = this.__options.whereCollection;
var tableName = this.__factory.tableName
, query = this.QueryInterface.update(this, tableName, values, identifier) , query = this.QueryInterface.update(this, tableName, values, identifier)
return query return query
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!