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

Commit 576e434f by Erik Seliger Committed by GitHub

fix(dateonly): set NULL correctly

1 parent e01cc2f8
......@@ -394,7 +394,7 @@ DATEONLY.prototype._stringify = function _stringify(date) {
};
DATEONLY.prototype._sanitize = function _sanitize(value, options) {
if (!options || options && !options.raw) {
if ((!options || options && !options.raw) && !!value) {
return moment(value).format('YYYY-MM-DD');
}
......
......@@ -730,6 +730,8 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
return this.task.getUsers();
}).then(_users => {
expect(_users).to.have.length(0);
}).finally(() => {
this.sequelize.options.omitNull = false;
});
});
......
......@@ -488,6 +488,33 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => {
});
});
it('should return set DATEONLY field to NULL correctly', function() {
const Model = this.sequelize.define('user', {
stamp: Sequelize.DATEONLY
});
const testDate = moment().format('YYYY-MM-DD');
return Model.sync({ force: true})
.then(() => Model.create({ stamp: testDate }))
.then(record => {
expect(typeof record.stamp).to.be.eql('string');
expect(record.stamp).to.be.eql(testDate);
return Model.findById(record.id);
}).then(record => {
expect(typeof record.stamp).to.be.eql('string');
expect(record.stamp).to.be.eql(testDate);
return record.update({
stamp: null
});
}).then(record => {
return record.reload();
}).then(record => {
expect(record.stamp).to.be.eql(null);
});
});
it('should be able to cast buffer as boolean', function() {
const ByteModel = this.sequelize.define('Model', {
byteToBool: this.sequelize.Sequelize.BLOB
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!