Fix bidirectional M2M
List fields on both ends of the same joiner compile but
stack-overflow at runtime on /api/list.
Example: books have :authors (M2M) and authors have :books
(M2M) on the same joiner. Then:
be-list(:books)
→ allowed-values → authors list field
→ be-list-column(:authors …) → be-list(:authors)
→ allowed-values → books list field
→ be-list(:books) ; infinite mutual recursion
Empty tables still hit this: be-list always builds
allowed-values via list-result. The request never completes,
so the frontend never gets create: true and the Add button
never appears (symptom of the failed list, not a separate
create-flag bug).
Root cause: allowed-values-for-field calls full be-list /
be-list-column on the related type. There is no cycle break.
(Also still uses :source, not :source-all — see separate
todo; that alone does not fix the recursion.)
****Goal:**** make bidirectional M2M work. Allowed-values for a list
field must load option rows without re-entering the full
be-list → allowed-values path on the other type (e.g. a
narrow options query / be-list-column path that skips nested
allowed-values, or an explicit recursion guard that still returns
usable options).
****Not the goal:**** a compile-time reject of two-sided list fields. Docs currently say "one-way M2M only" and known gap 11; those should flip to supported once fixed.
****Related****
- Multiple M2M per type (separate compiler SQL bug; plan
~/workbench/multiple-m2m-plan.org) — do not fold into this. allowed-valuesshould use:source-all— complementary; still need this fix after that lands.- Docs:
docs/model-reference.md→ Join tables ("One-way M2M only") and known gap 11.
****Workaround today:**** one-directional M2M only (owner has the list field; other side does not). Base model follows that (users→roles, not both ways).
****Impress-MVP note:**** not on the demo path (Model Bank / todos / books are one-way). Reputation footgun for AI-authored models; prefer a cheap guard if generator ships before full fix.
Fix:
lisp/backend.lisp— Added:skip-allowed-valueskeyword tolist-result,be-list, andbe-list-column(all keyword-only, no explicit nil defaults).allowed-values-for-fieldpasses:skip-allowed-values ttobe-list-column, breaking the mutual recursion cycle. Threelist-resultcall sites inbe-listupdated to pass keywords.models/test/bi-m2m-test.lisp— New fixture: books ↔ authors via one shared:book-authorsjoiner, both sides with:source-allnamed views.tests/bi-m2m-tests.lisp— New suite: 21 bi-m2m tests (compile, no-overflow, allowed-values, CRUD both directions, skip-flag, edge case) + 3 one-way regression tests underm2m-test.tests/helpers.lisp— Addedseed-bi-m2m-fixture,run-bi-m2m-tests, wired intorun-testsgroups.data-ui.asd— Registeredbi-m2m-tests.docs/model-reference.md— Replaced "One-way M2M only" with bidirectional pattern + example; marked gap 11 resolved; updated:source-allcross-reference.
Commit: 39e37e6 Fix bidirectional M2M
- Slot
- 24700
- Status
- 60 Done
- Tags
- mvp, backend, compiler, bug
- Contributors
- Donnie