Skip to content

Commit

Permalink
fix: Fix filtering on the wrong subtype. (#1082)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenh committed May 9, 2024
1 parent 35968ef commit 2e22bc2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/orm/src/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import { ReactiveReferenceImpl, Reference } from "./relations";
import { ReactiveFieldImpl } from "./relations/ReactiveField";
import { ReactiveQueryFieldImpl } from "./relations/ReactiveQueryField";
import { isCannotBeUpdatedRule } from "./rules";
import { fail } from "./utils";

const tagToConstructorMap = new Map<string, MaybeAbstractEntityConstructor<any>>();
const tableToMetaMap = new Map<string, EntityMetadata>();
const typeToMetaMap = new Map<string, EntityMetadata>();

/** Performs our boot-time initialization, i.e. hooking up reactivity. */
export function configureMetadata(metas: EntityMetadata[]): void {
Expand Down Expand Up @@ -40,6 +42,10 @@ export function getMetadataForTable(tableName: string): EntityMetadata {
return tableToMetaMap.get(tableName) ?? fail(`Unknown table ${tableName}`);
}

export function getMetadataForType(typeName: string): EntityMetadata {
return typeToMetaMap.get(typeName) ?? fail(`Unknown type ${typeName}`);
}

export function maybeGetConstructorFromReference(
value: string | Entity | Reference<any, any, any> | undefined,
): MaybeAbstractEntityConstructor<any> | undefined {
Expand All @@ -53,6 +59,7 @@ function populateConstructorMaps(metas: EntityMetadata[]): void {
if (!meta.baseType) tagToConstructorMap.set(meta.tagName, meta.cstr);
// Same for tables, but include subclass tables
tableToMetaMap.set(meta.tableName, meta);
typeToMetaMap.set(meta.type, meta);
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/orm/src/reactiveHints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getSubMetas,
} from "./EntityMetadata";
import { Changes, FieldStatus, ManyToOneFieldStatus } from "./changes";
import { getMetadataForType } from "./configure";
import { isChangeableField } from "./fields";
import { getProperties } from "./getProperties";
import { LoadHint, Loadable, Loaded } from "./loadHints";
Expand Down Expand Up @@ -424,7 +425,7 @@ function isTypeOrSubType(entity: Entity, typeName: string): boolean {
if (meta.type === typeName) return true;
// Otherwise see if the entity is a subtype of the typeName, i.e. if our poly/type
// filter is `@Publisher`, and we're a `SmallPublisher`, that's valid to traverse.
for (const other of getSubMetas(meta)) {
for (const other of getSubMetas(getMetadataForType(typeName))) {
if (other.type === typeName) return true;
}
return false;
Expand Down

0 comments on commit 2e22bc2

Please sign in to comment.