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

@@ -107,15 +107,15 @@ export class EntityManager<TBD extends object = DefaultDB> {
}
this._entities[entityIndex] = entity;
// caused issues because this.entity() was using a reference (for when initial config was given)
}
entity(e: Entity | keyof TBD | string): Entity {
let entity: Entity | undefined;
if (typeof e === "string") {
entity = this.entities.find((entity) => entity.name === e);
} else if (e instanceof Entity) {
entity = e;
}
// make sure to always retrieve by name
const entity = this.entities.find((entity) =>
e instanceof Entity ? entity.name === e.name : entity.name === e
);
if (!entity) {
// @ts-ignore