Fix entity referencing issue during post-seeded relational fetch

This commit is contained in:
dswbx
2025-01-10 17:28:43 +01:00
parent e94e8d8bd1
commit bb756548a6
11 changed files with 95 additions and 29 deletions

View File

@@ -46,10 +46,12 @@ export abstract class Module<Schema extends TSchema = TSchema, ConfigSchema = St
}
static ctx_flags = {
sync_required: false
sync_required: false,
ctx_reload_required: false
} as {
// signal that a sync is required at the end of build
sync_required: boolean;
ctx_reload_required: boolean;
};
onBeforeUpdate(from: ConfigSchema, to: ConfigSchema): ConfigSchema | Promise<ConfigSchema> {

View File

@@ -400,8 +400,8 @@ export class ModuleManager {
});
}
private async buildModules(options?: { graceful?: boolean }) {
this.logger.log("buildModules() triggered", options?.graceful, this._built);
private async buildModules(options?: { graceful?: boolean; ignoreFlags?: boolean }) {
this.logger.log("buildModules() triggered", options, this._built);
if (options?.graceful && this._built) {
this.logger.log("skipping build (graceful)");
return;
@@ -417,12 +417,25 @@ export class ModuleManager {
this._built = true;
this.logger.log("modules built", ctx.flags);
if (ctx.flags.sync_required) {
this.logger.log("db sync requested");
await ctx.em.schema().sync({ force: true });
await this.save();
ctx.flags.sync_required = false; // reset
if (options?.ignoreFlags !== true) {
if (ctx.flags.sync_required) {
ctx.flags.sync_required = false;
this.logger.log("db sync requested");
// sync db
await ctx.em.schema().sync({ force: true });
await this.save();
}
if (ctx.flags.ctx_reload_required) {
ctx.flags.ctx_reload_required = false;
this.logger.log("ctx reload requested");
this.ctx(true);
}
}
// reset all falgs
ctx.flags = Module.ctx_flags;
}
async build() {