From 8cad307fbb93d47fc1d35f6e07988ed126745dad Mon Sep 17 00:00:00 2001 From: ChengLei Shao Date: Fri, 18 Nov 2022 20:46:55 +0800 Subject: [PATCH] fix: create inherits from a table that has no id (#1104) * fix: create inherits from no id table * chore: console.log --- .../inhertits/collection-inherits.test.ts | 29 +++++++++++++++++++ packages/core/database/src/sync-runner.ts | 5 ++++ 2 files changed, 34 insertions(+) diff --git a/packages/core/database/src/__tests__/inhertits/collection-inherits.test.ts b/packages/core/database/src/__tests__/inhertits/collection-inherits.test.ts index 0f9489987..35224fe06 100644 --- a/packages/core/database/src/__tests__/inhertits/collection-inherits.test.ts +++ b/packages/core/database/src/__tests__/inhertits/collection-inherits.test.ts @@ -15,6 +15,35 @@ pgOnly()('collection inherits', () => { await db.close(); }); + it('should inherit from no id table', async () => { + const interfaceCollection = db.collection({ + name: 'a', + fields: [ + { + type: 'string', + name: 'name', + }, + ], + timestamps: false, + }); + + interfaceCollection.model.removeAttribute('id'); + const child = db.collection({ + name: 'b', + inherits: ['a'], + }); + + await db.sync(); + + const childInstance = await child.repository.create({ + values: { + name: 'test', + }, + }); + + expect(childInstance.get('name')).toBe('test'); + }); + it('should pass empty inherits params', async () => { const table1 = db.collection({ name: 'table1', diff --git a/packages/core/database/src/sync-runner.ts b/packages/core/database/src/sync-runner.ts index a1507e11d..a5c6acc47 100644 --- a/packages/core/database/src/sync-runner.ts +++ b/packages/core/database/src/sync-runner.ts @@ -40,6 +40,11 @@ export class SyncRunner { transaction, }, ); + + if (!sequenceNameResult[0].length) { + continue; + } + const columnDefault = sequenceNameResult[0][0]['column_default']; if (!columnDefault) {