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

Commit 43359bed by Ruben Bridgewater Committed by Jan Aagaard Meier

Fix upsert failing on not null checks (#6215)

1 parent b580d802
......@@ -22,6 +22,7 @@
- [CHANGED] `ignore` for create was renamed to `ignoreDuplicates` [#6138](https://github.com/sequelize/sequelize/issues/6138)
- [FIXED] Index names not quoted properly in `removeIndex` [#5888](https://github.com/sequelize/sequelize/issues/5888)
- [FIXED] `Int4` range not properly parsed [#5747](https://github.com/sequelize/sequelize/issues/5747)
- [FIXED] `upsert` does not fail anymore on not null validations [#5711](https://github.com/sequelize/sequelize/issues/5711)
## BC breaks:
- Range type bounds now default to [postgres default](https://www.postgresql.org/docs/9.5/static/rangetypes.html#RANGETYPES-CONSTRUCT) `[)` (inclusive, exclusive), previously was `()` (exclusive, exclusive)
......
......@@ -1965,7 +1965,7 @@ class Model {
}, Utils.cloneDeep(options || {}));
if (!options.fields) {
options.fields = Object.keys(this.attributes);
options.fields = Object.keys(values);
}
const createdAtAttr = this._timestampAttributes.createdAt
......@@ -1976,7 +1976,7 @@ class Model {
return instance.validate(options).then(() => {
// Map field names
const updatedDataValues = _.pick(instance.dataValues, Object.keys(instance._changed));
const insertValues = Utils.mapValueFieldNames(instance.dataValues, options.fields, this);
const insertValues = Utils.mapValueFieldNames(instance.dataValues, instance.attributes, this);
const updateValues = Utils.mapValueFieldNames(updatedDataValues, options.fields, this);
const now = Utils.now(this.sequelize.options.dialect);
......
'use strict';
/* jshint -W030 */
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/../support')
, current = Support.sequelize
, sinon = require('sinon')
, Promise = current.Promise
, DataTypes = require('../../../lib/data-types');
describe(Support.getTestDialectTeaser('Model'), function() {
if (current.dialect.supports.upserts) {
describe('method upsert', function () {
var User = current.define('User', {
name: DataTypes.STRING,
secretValue: {
type: DataTypes.INTEGER,
allowNull: false
}
});
before(function () {
this.query = current.query;
current.query = sinon.stub().returns(Promise.resolve());
});
after(function () {
current.query = this.query;
});
it('skip validations for missing fields', function() {
return expect(User.upsert({
name: 'Grumpy Cat'
})).not.to.be.rejectedWith(current.ValidationError);
});
});
}
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!