diff --git a/src/db/Model.ts b/src/db/Model.ts index e1dcf29..b635f2b 100644 --- a/src/db/Model.ts +++ b/src/db/Model.ts @@ -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 { + } + protected async beforeSave(exists: boolean, connection: Connection): Promise { } @@ -90,6 +97,7 @@ export default abstract class Model { } public async save(connection?: Connection, postHook?: (callback: () => Promise) => void): Promise { + await this.autoFill(); await this.validate(false, connection); const exists = await this.exists();