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

Commit b4ce0086 by Gabe Gorelick Committed by Sushant

fix(model/upsert): doesnt work with Infinity dates (#8397)

1 parent 6b116691
......@@ -2191,6 +2191,7 @@ class Model {
options = _.extend({
hooks: true
}, Utils.cloneDeep(options || {}));
options.model = this;
const createdAtAttr = this._timestampAttributes.createdAt;
const updatedAtAttr = this._timestampAttributes.updatedAt;
......
......@@ -487,6 +487,44 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
}
if (dialect.match(/^postgres/)) {
it('works when deletedAt is Infinity and part of primary key', function() {
const User = this.sequelize.define('User', {
name: {
type: DataTypes.STRING,
primaryKey: true
},
address: DataTypes.STRING,
deletedAt: {
type: DataTypes.DATE,
primaryKey: true,
allowNull: false,
defaultValue: Infinity
}
}, {
paranoid: true
});
return User.sync({ force: true }).then(() => {
return Promise.all([
User.create({ name: 'user1' }),
User.create({ name: 'user2', deletedAt: Infinity }),
// this record is soft deleted
User.create({ name: 'user3', deletedAt: -Infinity })
]).then(() => {
return User.upsert({ name: 'user1', address: 'address' });
}).then(() => {
return User.findAll({
where: { address: null }
});
}).then(users => {
expect(users).to.have.lengthOf(2);
});
});
});
}
});
}
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!