fix(infra): orm create override optional (#8627)

This commit is contained in:
EYHN
2024-10-29 09:18:14 +00:00
parent d71852789f
commit 8f95cc7b80
4 changed files with 8 additions and 4 deletions

View File

@@ -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);
});
});

View File

@@ -368,7 +368,7 @@ describe('ORM entity CRUD', () => {
name: 'test',
});
expect(user.email).toBe(null);
expect(user.email).toBe(undefined);
}
{

View File

@@ -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]);
}

View File

@@ -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;
}
}