Skip to content

server: an index finds an edge by the edge's name - #3

Merged
lesomnus merged 1 commit into
mainfrom
index-over-renamed-edge
Oct 9, 2026
Merged

lesomnus merged 1 commit into
mainfrom
index-over-renamed-edge

Conversation

@lesomnus

@lesomnus lesomnus commented Oct 9, 2026

Copy link
Copy Markdown
Member

Fixes #1.

What was wrong

pick<Entity> resolves each edge of a unique index through the target's Pick -- right -- but named the getter and the predicate after the target as well: k.GetUser() and HasUserWith for an edge called holder. protoc-gen-orm-service names the field of <Entity>RefBy<Index> after the edge, and ent names its predicate after the edge, so they only agreed when an edge is named after what it points at (tenant for a Tenant). Any other name generated a bare server that did not compile -- the two cases in #1.

What this changes

  • apps/server/app/x-pick.go: the Pick stays the target's (UserPick); the getter and the predicate are now the edge's (k.GetHolder(), seat.HasHolderWith).
  • proto/apptest/seat.proto: a Seat unique over two edges named otherwise than their targets (holder → User, org → Tenant) and over one nullable one (deputy → User) -- the composite and the single-edge shapes from the issue -- with everything generated from it.
  • internal/apptest/server/bare/x-indexedge_test.go: finds a seat by each index, and checks the composite one uses both edges (another holder in the same org is NotFound).

Nothing generated for the existing fixtures changes: their indexed edges are named after their targets, so the old and new names are the same.

Checked

What CI runs, locally: buf generate twice, go generate ./... in internal/apptest, go build, and go test ./... -count=1 at the root, in runtime and in internal/apptest -- the last also with APPTEST_POSTGRES against PostgreSQL 17.

Also seen, not changed here

A composite unique index with a timestamp among its fields returns from the pick at the timestamp instead of appending it, so the lookup drops the other fields. Filed as #2 rather than folded into this one.

🤖 Generated with Claude Code

A unique index over an edge resolves the edge through the target's Pick,
and named everything else after the target too: `k.GetUser()` and
`HasUserWith` for an edge called `holder`. The reference message is
generated with a field named after the edge and ent names its predicate
after the edge, so the two only agreed when an edge is named after what
it points at -- `tenant` for a Tenant -- and any other name generated a
bare server that did not compile.

The Pick stays the target's, since it is the target that is being found;
the getter and the predicate are now the edge's.

apptest gains a Seat, unique over two edges named otherwise than their
targets and over one nullable one, which is the shape a login on a
person has; and a test that finds a seat by each, and that both edges of
the composite index are in the predicate.

Fixes #1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lesomnus
lesomnus merged commit af03a00 into main Oct 9, 2026
2 checks passed
@lesomnus
lesomnus deleted the index-over-renamed-edge branch October 9, 2026 20:39
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.

A unique index over an edge named otherwise than its target generates a bare server that does not compile

1 participant