when the field migrate, load the collection options if is not in the database

This commit is contained in:
chenos 2020-12-11 10:37:43 +08:00
parent 880737c5c8
commit 3571f357cd
3 changed files with 8 additions and 22 deletions

View File

@ -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

View File

@ -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<TableOptions> {
return {
...this.get('options'),
name: this.get('name'),
title: this.get('title'),
...this.get(),
fields: await this.getFieldsOptions(),
};
}

View File

@ -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<FieldOptions> {
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({