You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 52d76f1
Browse filesBrowse the repository at this point in the historyBrowse files
feat(codegen-ts): reverse navigation via explicit FK finders (ADR-0038)
Implement the TS reference for ADR-0038 / ADR-0036 Wave 4: generate reverse
1:N navigation as explicit, typed FK query methods instead of lazy Drizzle
relations() collections, and fix the same-pair reverse-nav collision bug.
For each FK an entity E holds (identity.reference), E's queries module now
gains a finder pair, named by the FK FIELD (PascalCased, trailing `Id`
dropped) so it is unique within E by construction:
find<EPlural>By<FkField>(value) → SELECT … WHERE fk = ? (single, indexed)
find<EPlural>By<FkField>In(values) → SELECT … WHERE fk IN (…) (batched, anti-N+1)
The same-pair case (GameSession with 3 FKs to Scene) yields 3 distinct
finders — findGameSessionsByCurrentScene /
…ByLastOpeningNarrativeScene / …ByTransitioningFromScene — no collision.
Both finders are plain, framework-free, single-query reads returning E[].
Collision fix: the lazy reverse many() entries in relation-resolver
(named from the SOURCE entity, so two FKs same source→target silently
overwrote) are REMOVED — the explicit finders are the primitive per
ADR-0038. Forward one() relations and M:N many(junction) navigation are
unchanged.
- naming.ts: reverseFinderFnName / reverseFinderInFnName / reverseFinderFkSegment
(the cross-port naming SSOT).
- queries.ts: reverseFksFor + renderReverseFinderFns; wired into queries-file.
- reference/queries.ts (ADR-0034 scaffold-and-own copy) kept byte-identical.
- New fixtures/conformance/reverse-finders-same-pair (3 FKs to Scene + a
string-PK FK to Player) gates the metadata cross-port; reverse-finders.test.ts
asserts the generated finder names incl. the same-pair case.
- Regenerated golden + package-layout snapshots (additive finders; reverse
many() blocks dropped). Registry-conformance unaffected (no new vocab).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GF9xLEQZaPus5Y6opk398n
0 commit comments