diff --git a/packages/database/src/model.ts b/packages/database/src/model.ts index d8de02fe4..e70453019 100644 --- a/packages/database/src/model.ts +++ b/packages/database/src/model.ts @@ -228,7 +228,7 @@ export abstract class Model extends SequelizeModel { alias || Utils.underscoredIf(`${association}Count`, this.options.underscored), ].filter(Boolean); - return attribute as ProjectionAlias; + return attribute as unknown as ProjectionAlias; } /** diff --git a/packages/database/src/table.ts b/packages/database/src/table.ts index 52e608375..e12f24941 100644 --- a/packages/database/src/table.ts +++ b/packages/database/src/table.ts @@ -151,6 +151,7 @@ export class Table { this.defaultModel = getRegisteredModel(model); this.modelAttributes = {}; // 在 set fields 之前 model init 的原因是因为关系字段可能需要用到 model 的相关配置 + // @ts-ignore this.addIndexes(indexes, 'modelOnly'); // this.modelInit('modelOnly'); this.setFields(fields); @@ -330,15 +331,13 @@ export class Table { /** * 添加索引 * - * @param options + * @param indexOptions * @param reinitialize */ - public addIndex(options: string | ModelIndexesOptions, reinitialize: Reinitialize = true) { - if (typeof options === 'string') { - options = { - fields: [options], - }; - } + public addIndex(indexOptions: string | ModelIndexesOptions, reinitialize: Reinitialize = true) { + const options = typeof indexOptions === 'string' ? { + fields: [indexOptions], + } : indexOptions; // @ts-ignore const index = Utils.nameIndex(options, this.options.name); console.log(this.options, { index, options }); @@ -386,6 +385,7 @@ export class Table { for (const key in fields) { this.addField(fields[key], false); } + // @ts-ignore this.addIndexes(indexes, false); this.modelInit(true); } diff --git a/packages/plugin-collections/src/models/collection.ts b/packages/plugin-collections/src/models/collection.ts index 003ebe745..37489226f 100644 --- a/packages/plugin-collections/src/models/collection.ts +++ b/packages/plugin-collections/src/models/collection.ts @@ -167,9 +167,11 @@ export class CollectionModel extends BaseModel { }); } if (collection && update) { + // @ts-ignore await collection.update(data, options); } if (!collection) { + // @ts-ignore collection = await this.create(data, options); } const associations = ['fields', 'tabs', 'actions', 'views']; @@ -211,11 +213,15 @@ export class CollectionModel extends BaseModel { await model.update({...item, sort: index+1}, options); } if (!model) { - model = await Model.create({ - ...item, - sort: index+1, - collection_name: collection.name, - }, options); + model = await Model.create( + { + ...item, + sort: index+1, + collection_name: collection.name, + }, + // @ts-ignore + options + ); } if (model) { if (key === 'tabs') { diff --git a/packages/plugin-collections/src/models/field.ts b/packages/plugin-collections/src/models/field.ts index e4cf5be71..13e319d9e 100644 --- a/packages/plugin-collections/src/models/field.ts +++ b/packages/plugin-collections/src/models/field.ts @@ -1,12 +1,11 @@ import _ from 'lodash'; import BaseModel from './base'; -import { FieldOptions } from '@nocobase/database'; +import { FieldOptions, BELONGSTO, BELONGSTOMANY, HASMANY } from '@nocobase/database'; import * as types from '../interfaces/types'; import { merge } from '../utils'; import { BuildOptions } from 'sequelize'; import { SaveOptions, Utils } from 'sequelize'; import { generateCollectionName } from './collection'; -import { BELONGSTO, BELONGSTOMANY, HASMANY } from '@nocobase/database'; interface FieldImportOptions extends SaveOptions { parentId?: number; @@ -243,10 +242,14 @@ export class FieldModel extends BaseModel { } else { tmp.collection_name = collectionName; } - model = await this.create({ - ...item, - ...tmp, - }, options); + model = await this.create( + { + ...item, + ...tmp, + }, + //@ts-ignore + options + ); } if (Array.isArray(item.children)) { const childrenIds = await this.import(item.children, { diff --git a/packages/plugin-collections/src/models/page.ts b/packages/plugin-collections/src/models/page.ts index 085fdeb44..4daea6999 100644 --- a/packages/plugin-collections/src/models/page.ts +++ b/packages/plugin-collections/src/models/page.ts @@ -23,10 +23,14 @@ export class PageModel extends BaseModel { }, }); if (!page) { - page = await this.create({ - ...item, - parent_id: parentId, - }, options); + page = await this.create( + { + ...item, + parent_id: parentId, + }, + // @ts-ignore + options + ); } if (Array.isArray(item.children)) { await this.import(item.children, {