Skip to content

Commit

Permalink
fix: Fix reacting to subtype-only relations. (#1079)
Browse files Browse the repository at this point in the history
If we saw a hint like:

* child (no subtypes) -> parent (that is a subtype) -> something else

When we would reverse it, and try to go:

* something else -> parent (that is a different subtype) -> children

The `parent[children]` would blow up, b/c that o2m may not exist.

This is very similar to conditionally walking through polys, so we
reuse the same `parent@Subtype` to infra to stop the walking before
trying to access `parent[children]`.
  • Loading branch information
stephenh committed May 8, 2024
1 parent b8e05a4 commit 368a9be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/orm/src/reactiveHints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export function reverseReactiveHint<T extends Entity>(
case "o2o": {
const isOtherReadOnly = field.otherMetadata().allFields[field.otherFieldName].immutable;
const otherFieldName =
field.otherMetadata().allFields[field.otherFieldName].kind === "poly"
field.otherMetadata().allFields[field.otherFieldName].kind === "poly" || meta.baseType
? `${field.otherFieldName}@${meta.type}`
: field.otherFieldName;
// This is not a field, but we want our reverse side to be reactive, so pass reactForOtherSide
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,13 @@ describe("EntityManager.reactiveRules", () => {
fn,
},
// SmallPublisher's "cannot have >5 authors" rule
{ cstr: "SmallPublisher", name: sm(/Publisher.ts:\d+/), fields: ["publisher"], path: ["publisher"], fn },
{
cstr: "SmallPublisher",
name: sm(/Publisher.ts:\d+/),
fields: ["publisher"],
path: ["publisher@SmallPublisher"],
fn,
},
]);

expect(getReactiveRules(Book)).toMatchObject([
Expand Down

0 comments on commit 368a9be

Please sign in to comment.