Skip to content
This repository was archived by the owner on Apr 17, 2020. It is now read-only.

Commit cd3514c

Browse files
thyenjoelmukuthu
authored andcommitted
fix: do not stringify null values (#124)
fix: do not stringify null values when casting for save
1 parent 7f3eba9 commit cd3514c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/KnormPostgres.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class KnormPostgres {
2121
(this.type === 'json' || this.type === 'jsonb') &&
2222
!(value instanceof knorm.Query.prototype.sql) &&
2323
options.forSave &&
24-
!(this.castors && this.castors.forSave)
24+
!(this.castors && this.castors.forSave) &&
25+
value !== null
2526
) {
2627
return JSON.stringify(value);
2728
}

test/KnormPostgres.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ describe('KnormPostgres', () => {
169169
Query.prototype.sql = sql;
170170
});
171171

172+
it('does not stringify `null` values', () => {
173+
const field = new Field({ name: 'foo', model: Model, type: 'json' });
174+
expect(field.cast(null, null, { forSave: true }), 'to be undefined');
175+
});
176+
172177
describe('with a forSave cast function configured', () => {
173178
it('uses the configred function', () => {
174179
const field = new Field({

0 commit comments

Comments
 (0)