Models: add autoFill method for asynchronous default value load
This commit is contained in:
parent
4ab615c457
commit
f47f01f147
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user