From 4657c22ef39f84293ca07459a20a908418296cd3 Mon Sep 17 00:00:00 2001 From: chenos Date: Tue, 22 Feb 2022 16:11:19 +0800 Subject: [PATCH] fix(database): create collections with field via http api --- packages/plugin-collection-manager/src/models/field.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/plugin-collection-manager/src/models/field.ts b/packages/plugin-collection-manager/src/models/field.ts index cd6290247..5c9a81347 100644 --- a/packages/plugin-collection-manager/src/models/field.ts +++ b/packages/plugin-collection-manager/src/models/field.ts @@ -1,5 +1,5 @@ -import { SyncOptions, Transactionable } from 'sequelize'; import Database, { MagicAttributeModel } from '@nocobase/database'; +import { SyncOptions, Transactionable } from 'sequelize'; interface LoadOptions extends Transactionable { // TODO @@ -15,7 +15,7 @@ export class FieldModel extends MagicAttributeModel { const { skipExist = false } = loadOptions || {}; const collectionName = this.get('collectionName'); if (!this.db.hasCollection(collectionName)) { - throw new Error(`${collectionName} collection does not exist.`); + return; } const collection = this.db.getCollection(collectionName); const name = this.get('name'); @@ -29,6 +29,9 @@ export class FieldModel extends MagicAttributeModel { const field = await this.load({ transaction: options.transaction, }); + if (!field) { + return; + } await field.sync(options); } }