Models: add autoFill method for asynchronous default value load

This commit is contained in:
Alice Gaudon 2020-08-28 14:16:06 +02:00
parent 4ab615c457
commit f47f01f147

View File

@ -83,6 +83,13 @@ export default abstract class Model {
}
}
/**
* Override this to automatically fill obvious missing data i.e. from relation or default value that are fetched
* asynchronously.
*/
public async autoFill(): Promise<void> {
}
protected async beforeSave(exists: boolean, connection: Connection): Promise<void> {
}
@ -90,6 +97,7 @@ export default abstract class Model {
}
public async save(connection?: Connection, postHook?: (callback: () => Promise<void>) => void): Promise<void> {
await this.autoFill();
await this.validate(false, connection);
const exists = await this.exists();