mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-22 19:53:48 +08:00
fix(infra): orm create override optional (#8627)
This commit is contained in:
@@ -125,6 +125,6 @@ describe('ORM hook mixin', () => {
|
|||||||
// @ts-expect-error private
|
// @ts-expect-error private
|
||||||
const rawTag = client.tags.adapter.data.get(tag.id);
|
const rawTag = client.tags.adapter.data.get(tag.id);
|
||||||
expect(rawTag.color).toBe('red');
|
expect(rawTag.color).toBe('red');
|
||||||
expect(rawTag.colors).toBe(null);
|
expect(rawTag.colors).toBe(undefined);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -368,7 +368,7 @@ describe('ORM entity CRUD', () => {
|
|||||||
name: 'test',
|
name: 'test',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(user.email).toBe(null);
|
expect(user.email).toBe(undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -64,6 +64,10 @@ export class YjsTableAdapter implements TableAdapter {
|
|||||||
|
|
||||||
this.doc.transact(() => {
|
this.doc.transact(() => {
|
||||||
for (const key in data) {
|
for (const key in data) {
|
||||||
|
if (data[key] === undefined) {
|
||||||
|
// skip undefined fields, avoid unexpected override
|
||||||
|
continue;
|
||||||
|
}
|
||||||
record.set(key, data[key]);
|
record.set(key, data[key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -160,11 +160,11 @@ export class Table<T extends TableSchemaBuilder> {
|
|||||||
|
|
||||||
if (inputVal === undefined) {
|
if (inputVal === undefined) {
|
||||||
if (schema.optional) {
|
if (schema.optional) {
|
||||||
acc[key] = null;
|
acc[key] = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (schema.default) {
|
if (schema.default) {
|
||||||
acc[key] = schema.default() ?? null;
|
acc[key] = schema.default() ?? undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user