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

Commit b326c478 by Thaddeus Quintin

Make primary key an _undefined_ check instead of truthy.

created integration test that checks basic usage
1 parent f859e2e7
...@@ -538,7 +538,7 @@ Instance.prototype.save = function(options) { ...@@ -538,7 +538,7 @@ Instance.prototype.save = function(options) {
} }
if (this.isNewRecord === false) { if (this.isNewRecord === false) {
if (primaryKeyName && !this.get(primaryKeyName, {raw: true})) { if (primaryKeyName && this.get(primaryKeyName, {raw: true}) === undefined) {
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'); 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');
} }
} }
......
...@@ -898,6 +898,38 @@ describe(Support.getTestDialectTeaser('Instance'), function() { ...@@ -898,6 +898,38 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
}); });
}); });
it('handles an entry with primaryKey of zero', function() {
var username = 'user'
, newUsername = 'newUser'
, User2 = this.sequelize.define('User2',
{
id: {
type: DataTypes.INTEGER.UNSIGNED,
autoIncrement: false,
primaryKey: true
},
username: { type: DataTypes.STRING }
});
return User2.sync().then(function () {
return User2.create({id: 0, username: username}).then(function (user){
expect(user).to.be.ok;
expect(user.id).to.equal(0);
expect(user.username).to.equal(username);
return User2.findById(0).then(function (user) {
expect(user).to.be.ok;
expect(user.id).to.equal(0);
expect(user.username).to.equal(username);
return user.updateAttributes({username: newUsername}).then(function (user) {
expect(user).to.be.ok;
expect(user.id).to.equal(0);
expect(user.username).to.equal(newUsername);
});
});
});
});
});
it('updates the timestamps', function() { it('updates the timestamps', function() {
var now = Date.now() var now = Date.now()
, user = null , user = null
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!