Skip to content

docs(schema): correct from+to relationship cardinality to many-to-one - #602

Merged
Ethan-Arrowood merged 3 commits into
mainfrom
docs/relationship-from-to-cardinality
Jul 29, 2026
Merged

docs(schema): correct from+to relationship cardinality to many-to-one#602
Ethan-Arrowood merged 3 commits into
mainfrom
docs/relationship-from-to-cardinality

Conversation

@kriszyp

@kriszyp kriszyp commented Jul 22, 2026

Copy link
Copy Markdown
Member

What

Fixes the second bug from #582: the @relationship(from: attribute, to: attribute) example in reference/database/schema.md joins two scalar fields (productSku -> sku) but was described as "useful for many-to-many relationships." Reworded the section to state that cardinality follows the to attribute (scalar -> many-to-one, array -> many-to-many via the array pattern already shown in the from-only section above), and relabeled the example's inline comment as many-to-one.

Why

Per #582: Harper's search.ts decides many-to-many purely by whether the target to attribute is an array (isManyToMany = Boolean(findAttribute(relatedTable.attributes, attribute.relationship.to)?.elements)). A scalar-to-scalar from+to join can never be many-to-many, so the old text mislabeled the example and could mislead readers (and downstream agent-rules generation in HarperFast/skills) into modeling it wrong.

The issue's first finding (reference/rest/querying.md pointing from at singular resellerId instead of resellerIds) was already fixed on main by 7e373fa prior to this dispatch — no change needed here.

Test plan

  • npx prettier --check reference/database/schema.md reference/rest/querying.md — passes
  • Verified against ~/dev/harper's search.ts isManyToMany logic per the issue's citation

Refs #582

🤖 Generated with Claude Code

The @relationship(from:, to:) example joined two scalar attributes
(productSku -> sku) but was labeled "useful for many-to-many
relationships" — cardinality in Harper is decided by whether the
target `to` attribute is an array (search.ts's isManyToMany check),
so a scalar-to-scalar join is many-to-one, not many-to-many.

The other bug in issue #582 (querying.md resellers example pointing
`from` at the singular resellerId) was already fixed on main by
7e373fa before this dispatch ran.

Refs #582

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the documentation in reference/database/schema.md to clarify the cardinality rules for foreign key to foreign key relationships using @relationship(from: attribute, to: attribute). The review feedback correctly identifies an inaccuracy in the explanation of how cardinality is determined and provides a clearer, simplified phrasing to resolve the issue.

Comment thread reference/database/schema.md Outdated
@github-actions
github-actions Bot temporarily deployed to pr-602 July 22, 2026 21:33 Inactive
@github-actions

Copy link
Copy Markdown

🚀 Preview Deployment

Your preview deployment is ready!

🔗 Preview URL: https://preview.harper-documentation.harperfabric.com/pr-602

This preview will update automatically when you push new commits.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@kriszyp
kriszyp marked this pull request as ready for review July 22, 2026 22:37
@kriszyp
kriszyp requested a review from a team as a code owner July 22, 2026 22:37
@github-actions

Copy link
Copy Markdown

🚀 Preview Deployment

Your preview deployment is ready!

🔗 Preview URL: https://preview.harper-documentation.harperfabric.com/pr-602

This preview will update automatically when you push new commits.

@github-actions
github-actions Bot temporarily deployed to pr-602 July 22, 2026 22:40 Inactive
Comment thread reference/database/schema.md Outdated
Table.ts wires the @relationship resolver for any attribute with `to`
set (from+to or to-only) only when the field itself has an array type
(attribute.elements?.definition); the scalar `product: Product` field
never registers a resolver and 500s on select. Match the field type to
what Harper actually requires, and drop the many-to-one cardinality
claim in favor of describing the actual resolve behavior.

Refs #582

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

🚀 Preview Deployment

Your preview deployment is ready!

🔗 Preview URL: https://preview.harper-documentation.harperfabric.com/pr-602

This preview will update automatically when you push new commits.

@github-actions
github-actions Bot temporarily deployed to pr-602 July 27, 2026 13:57 Inactive

@Ethan-Arrowood Ethan-Arrowood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified against the resolver in Table.ts on main — the corrected array-typed to example matches actual behavior. One nit: title still says "many-to-one".

sent with Claude Fable 5

@Ethan-Arrowood
Ethan-Arrowood merged commit a19158f into main Jul 29, 2026
7 checks passed
@Ethan-Arrowood
Ethan-Arrowood deleted the docs/relationship-from-to-cardinality branch July 29, 2026 14:54
@github-actions

Copy link
Copy Markdown

🧹 Preview Cleanup

The preview deployment for this PR has been removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants