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

Commit f5dc34fa by Mick Hansen

fix(instance): make it impossible to save instances without a primary key value …

…(if a primary key is defined), closes #3353
1 parent 047acc4b
......@@ -535,6 +535,12 @@ module.exports = (function() {
}
}
if (this.isNewRecord === false) {
if (primaryKeyName && !this.get(primaryKeyName, {raw: true})) {
throw new Error('You attempted to save an instance with no primary key, this is not allowed since it would result in a global update');
}
}
return Promise.bind(this).then(function() {
// Validate
if (options.validate) {
......
'use strict';
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/../support')
, DataTypes = require(__dirname + '/../../../lib/data-types')
, current = Support.sequelize;
describe(Support.getTestDialectTeaser('Instance'), function() {
describe('save', function () {
it('should disallow saves if no primary key values is present', function () {
var Model = current.define('User', {
})
, instance;
instance = Model.build({}, {isNewRecord: false});
expect(function () {
instance.save()
}).to.throw();
});
});
});
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!