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

Commit 493528af by Jan Aagaard Meier

Merge pull request #3864 from FredKSchott/upsert-function-defaults-broken

Fix issue where upsert fails for database function values
2 parents c6df537d 08ed3756
......@@ -95,6 +95,8 @@ var Utils = module.exports = {
},
cloneDeep: function(obj, fn) {
return lodash.cloneDeep(obj, function (elem) {
// Preserve special data-types like `fn` across clones. _.get() is used for checking up the prototype chain
if (!!Utils._.get(elem, 'clone') && typeof elem.clone === 'function') {return elem.clone(); }
// Unfortunately, lodash.cloneDeep doesn't preserve Buffer.isBuffer, which we have to rely on for binary data
if (Buffer.isBuffer(elem)) { return elem; }
......@@ -421,4 +423,8 @@ Utils.fn.prototype._isSequelizeMethod =
Utils.col.prototype._isSequelizeMethod =
Utils.json.prototype._isSequelizeMethod = true;
Utils.fn.prototype.clone = function() {
return new Utils.fn(this.fn, this.args);
};
Utils.Promise = require('./promise');
......@@ -223,6 +223,31 @@ describe(Support.getTestDialectTeaser('Model'), function() {
expect(user.baz).to.equal('oof');
});
});
it('works with database functions', function() {
return this.User.upsert({ id: 42, username: 'john', foo: this.sequelize.fn('upper', 'mixedCase1')}).bind(this).then(function(created) {
if (dialect === 'sqlite') {
expect(created).to.be.undefined;
} else {
expect(created).to.be.ok;
}
return this.sequelize.Promise.delay(1000).bind(this).then(function() {
return this.User.upsert({ id: 42, username: 'doe', foo: this.sequelize.fn('upper', 'mixedCase2') });
});
}).then(function(created) {
if (dialect === 'sqlite') {
expect(created).to.be.undefined;
} else {
expect(created).not.to.be.ok;
}
return this.User.findById(42);
}).then(function(user) {
expect(user.createdAt).to.be.ok;
expect(user.username).to.equal('doe');
expect(user.foo).to.equal('MIXEDCASE2');
});
});
});
}
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!