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

Commit 0ce88c47 by Jerome C

By default, all attributes except 'createdAt' can be updated

1 parent 51e77239
...@@ -198,7 +198,7 @@ module.exports = (function() { ...@@ -198,7 +198,7 @@ module.exports = (function() {
')'); ')');
}.bind(this)); }.bind(this));
if (options && options.updateOnDuplicate instanceof Array && options.updateOnDuplicate.length) { if (options && options.updateOnDuplicate) {
onDuplicateKeyUpdate += ' ON DUPLICATE KEY UPDATE ' + options.updateOnDuplicate.map(function(attr) { onDuplicateKeyUpdate += ' ON DUPLICATE KEY UPDATE ' + options.updateOnDuplicate.map(function(attr) {
var key = this.quoteIdentifier(attr); var key = this.quoteIdentifier(attr);
return key + '=VALUES(' + key + ')'; return key + '=VALUES(' + key + ')';
......
...@@ -1232,7 +1232,7 @@ module.exports = (function() { ...@@ -1232,7 +1232,7 @@ module.exports = (function() {
* @param {Boolean} [options.hooks=true] Run before / after bulk create hooks? * @param {Boolean} [options.hooks=true] Run before / after bulk create hooks?
* @param {Boolean} [options.individualHooks=false] Run before / after create hooks for each individual Instance? BulkCreate hooks will still be run if options.hooks is true. * @param {Boolean} [options.individualHooks=false] Run before / after create hooks for each individual Instance? BulkCreate hooks will still be run if options.hooks is true.
* @param {Boolean} [options.ignoreDuplicates=false] Ignore duplicate values for primary keys? (not supported by postgres) * @param {Boolean} [options.ignoreDuplicates=false] Ignore duplicate values for primary keys? (not supported by postgres)
* @param {Boolean} [options.updateOnDuplicate] Fields to update if row key already exists (on duplicate key update)? (only supported by mysql & mariadb) * @param {Array} [options.updateOnDuplicate] Fields to update if row key already exists (on duplicate key update)? (only supported by mysql & mariadb). By default, all fields are updated.
* *
* @return {Promise<Array<Instance>>} * @return {Promise<Array<Instance>>}
*/ */
...@@ -1266,6 +1266,15 @@ module.exports = (function() { ...@@ -1266,6 +1266,15 @@ module.exports = (function() {
return Promise.reject(new Error(dialect + ' does not support the \'updateOnDuplicate\' option.')); return Promise.reject(new Error(dialect + ' does not support the \'updateOnDuplicate\' option.'));
} }
if (options.updateOnDuplicate) {
// By default, all attributes except 'createdAt' can be updated
var updatableFields = Utils._.pull(Object.keys(this.tableAttributes), 'createdAt');
if (Utils._.isArray(options.updateOnDuplicate) && !Utils._.isEmpty(options.updateOnDuplicate)) {
updatableFields = Utils._.intersection(updatableFields, options.updateOnDuplicate);
}
options.updateOnDuplicate = updatableFields;
}
var self = this var self = this
, createdAtAttr = this._timestampAttributes.createdAt , createdAtAttr = this._timestampAttributes.createdAt
, updatedAtAttr = this._timestampAttributes.updatedAt , updatedAtAttr = this._timestampAttributes.updatedAt
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!