-
Notifications
You must be signed in to change notification settings - Fork 9
docs(schema): correct from+to relationship cardinality to many-to-one #602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kriszyp
wants to merge
2
commits into
main
Choose a base branch
from
docs/relationship-from-to-cardinality
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2
−2
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
High: the corrected example does not actually work in Harper
Relabeling the join as many-to-one is directionally right for the intended cardinality, but the schema as written doesn't resolve at all on current
main(513f87471), regardless of label.Table.ts's attribute-wiring (updatedAttributes(), aroundresources/Table.ts:4414-4450) isif (relationship.to) { if (attribute.elements?.definition) {...} } else if (relationship.from) {...}. Sinceto: skuis set, it takes the first branch unconditionally — and becauseproduct: Productis a scalar field (noattribute.elements), that branch'selsefires:console.error('...must have an array type referencing a table as the elements'), andattribute.resolveis leftnull. Theelse if (relationship.from)branch — the one that actually knows how to resolve a single scalar relationship — is never reached whentois also set.I verified this empirically against a live instance built from
origin/mainwith this exact schema:GET /OrderItem/:id(no select) silently omitsproductfrom the response entirely (not evennull), andGET /OrderItem/:id?select(...,product{...})(the standard way to expand a relationship, as used elsewhere in these docs/tests) 500s withTypeError: Cannot read properties of undefined (reading 'propertyResolvers')inResource.ts(transformForSelect), because it dereferencesattribute.resolve.definitionon anullresolve.The combined
from+toresolver path only registers when the field type is an array (attribute.elements?.definition) — there is no code path that resolves a scalar foreign-key-to-foreign-key relationship by a non-primary-keytoattribute. So the fix that actually makes this example work isproducts: [Product] @relationship(from: productSku, to: sku)(array field), not a comment/prose relabel — and once it's array-typed, it's structurally a one-to-many/many-to-many resolver in the code regardless of how uniqueskuis in practice.This is a pre-existing bug in the example (not introduced by this PR), but the PR's stated purpose is specifically to make this example accurate, and its test plan only checked
search.ts'sisManyToMany(the query-filter cardinality calc), notTable.ts's resolver wiring (the code path that determines whether the field resolves at all). Worth fixing before merge so the docs don't keep shipping a schema that 500s when a reader follows it.Suggested fix: change the field to an array type (
products: [Product] @relationship(from: productSku, to: sku)) and update the surrounding prose (line 400) accordingly, or drop thetoargument and this section's non-primary-key framing until Harper actually supports scalar-target foreign-key-to-foreign-key resolution.—
Generated by Barber AI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This issue sounds legit.