mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
Fix entity referencing issue during post-seeded relational fetch
This commit is contained in:
@@ -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> {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user