Skip to content

Commit

Permalink
fix(infra): orm create override optional (#8627)
Browse files Browse the repository at this point in the history
  • Loading branch information
EYHN committed Oct 29, 2024
1 parent d718527 commit 8f95cc7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/common/infra/src/orm/core/__tests__/hook.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,6 @@ describe('ORM hook mixin', () => {
// @ts-expect-error private
const rawTag = client.tags.adapter.data.get(tag.id);
expect(rawTag.color).toBe('red');
expect(rawTag.colors).toBe(null);
expect(rawTag.colors).toBe(undefined);
});
});
2 changes: 1 addition & 1 deletion packages/common/infra/src/orm/core/__tests__/yjs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ describe('ORM entity CRUD', () => {
name: 'test',
});

expect(user.email).toBe(null);
expect(user.email).toBe(undefined);
}

{
Expand Down
4 changes: 4 additions & 0 deletions packages/common/infra/src/orm/core/adapters/yjs/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export class YjsTableAdapter implements TableAdapter {

this.doc.transact(() => {
for (const key in data) {
if (data[key] === undefined) {
// skip undefined fields, avoid unexpected override
continue;
}
record.set(key, data[key]);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/common/infra/src/orm/core/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ export class Table<T extends TableSchemaBuilder> {

if (inputVal === undefined) {
if (schema.optional) {
acc[key] = null;
acc[key] = undefined;
}

if (schema.default) {
acc[key] = schema.default() ?? null;
acc[key] = schema.default() ?? undefined;
}
}

Expand Down

0 comments on commit 8f95cc7

Please sign in to comment.