diff --git a/packages/plugin-collections/src/models/base.ts b/packages/plugin-collections/src/models/base.ts index 4a9effa83..24d31379f 100644 --- a/packages/plugin-collections/src/models/base.ts +++ b/packages/plugin-collections/src/models/base.ts @@ -78,7 +78,7 @@ export class BaseModel extends Model { // 不处理关系数据 // @ts-ignore if (_.get(this.constructor.associations, key)) { - return this; + return super.set(key, value, options); } // 如果是 object 数据,merge 处理 if (_.isPlainObject(value)) { @@ -112,7 +112,7 @@ export class BaseModel extends Model { // 不处理关系数据 // @ts-ignore if (_.get(this.constructor.associations, key)) { - return this; + return super.setDataValue(key, value); } if (_.isPlainObject(value)) { // @ts-ignore diff --git a/packages/plugin-collections/src/models/collection.ts b/packages/plugin-collections/src/models/collection.ts index ec73d2d9d..989102a48 100644 --- a/packages/plugin-collections/src/models/collection.ts +++ b/packages/plugin-collections/src/models/collection.ts @@ -35,12 +35,6 @@ export class CollectionModel extends BaseModel { this.set('name', generateCollectionName()); } - generateNameIfNull() { - if (!this.get('name')) { - this.generateName(); - } - } - /** * 通过 name 获取 collection * @@ -109,9 +103,7 @@ export class CollectionModel extends BaseModel { async getOptions(): Promise { return { - ...this.get('options'), - name: this.get('name'), - title: this.get('title'), + ...this.get(), fields: await this.getFieldsOptions(), }; } diff --git a/packages/plugin-collections/src/models/field.ts b/packages/plugin-collections/src/models/field.ts index 815e75df0..e70e298f0 100644 --- a/packages/plugin-collections/src/models/field.ts +++ b/packages/plugin-collections/src/models/field.ts @@ -33,12 +33,6 @@ export class FieldModel extends BaseModel { this.set('name', generateFieldName()); } - generateNameIfNull() { - if (!this.get('name')) { - this.generateName(); - } - } - setInterface(value) { const { options } = types[value]; let args = []; @@ -55,11 +49,7 @@ export class FieldModel extends BaseModel { } async getOptions(): Promise { - return { - ...this.get('options'), - type: this.get('type'), - name: this.get('name'), - }; + return this.get(); } async migrate(options: any = {}) { @@ -67,6 +57,10 @@ export class FieldModel extends BaseModel { if (!collectionName) { return false; } + // 如果 database 未定义,load 出来 + if (!this.database.isDefined(collectionName)) { + await this.database.getModel('collections').load({where: {name: collectionName}}); + } const table = this.database.getTable(collectionName); table.addField(await this.getOptions()); await table.sync({