when the field migrate, load the collection options if is not in the database
This commit is contained in:
parent
880737c5c8
commit
3571f357cd
@ -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
|
||||
|
@ -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(),
|
||||
};
|
||||
}
|
||||
|
@ -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({
|
||||
|
Loading…
Reference in New Issue
Block a user