Skip to content

Add Many-to-Any (M2A) field support (#60)#62

Merged
smartlabsAT merged 4 commits into
mainfrom
feature/issue-60-m2a-support
Jun 1, 2026
Merged

Add Many-to-Any (M2A) field support (#60)#62
smartlabsAT merged 4 commits into
mainfrom
feature/issue-60-m2a-support

Conversation

@smartlabsAT
Copy link
Copy Markdown
Owner

Summary

Adds Many-to-Any (M2A) relationship support to the Super Table layout. Resolves #60.

Previously, M2A fields rendered the raw display template (or an empty cell), and adding a Column Display override on an M2A field blanked the entire table with a 403. Both are fixed, and M2A now renders correctly alongside the existing relation types.

What changed

M2A display & query

  • expandTokensThroughRelation now handles M2A: it emits the collection discriminator plus per-collection item:<collection>.<field> paths and drops bare/disallowed tokens, so the items request can no longer 403.
  • New resolveM2ARelation util centralises the junction-shape lookup (discriminator, item field, allowed collections).
  • New renderM2ATemplate util resolves {{collection}} and {{item:col.field}} tokens per junction row, sharing parseM2AToken with the query side so the two cannot drift.

Permissions

  • When a target collection is not readable, that row shows a block icon — only on genuine permission denial, not on a dangling FK.
  • resolveM2ARelation falls back to junction_field + the field's allowedCollections when Directus filters the polymorphic relation out, so a restricted user still sees what they can read.
  • Read-but-no-write users keep relational fields read-only (unchanged).

Robustness & UX

  • In-body error state: a failed items request no longer leaves a blank body under a live pagination bar.
  • The Column Display editor shows a help icon + hint with the field's allowed collections for M2A fields.

Docs

  • README documents M2A + a "Column Displays" usage section, and corrects outdated sections verified against the code.

Out of scope

Inline editing of relational fields (M2O/O2M/M2M/M2A) — tracked in #61. Relational fields remain display-only by design.

Testing

  • 233 unit tests pass (pnpm run test); pnpm run quality green.
  • Manual Playwright run covered: M2A & M2M display, orders_simple, the M2A relationship is not displayed correctly #60 column-display repro, the error state, the inline-edit contract, pagination + row navigation, restricted-permission (blocked collection + dangling FK), read-only user, and the editor hint.
  • Regression: all scalar field types, M2M/M2O, and translations (incl. a translation row carrying a nested M2M) render unchanged.

Render and query M2A relations in the table. M2A fields previously showed
the raw display template (or an empty cell) and a column-display override
on them blanked the whole table with a 403.

- expandTokensThroughRelation now handles M2A: emits the collection
  discriminator plus per-collection `item:<collection>.<field>` paths,
  dropping bare/disallowed tokens so the items request can't 403.
- New resolveM2ARelation helper centralises the junction-shape lookup
  (discriminator, item field, allowed collections) with a permission
  fallback: when the polymorphic relation is filtered out, it reconstructs
  the shape from junction_field + the field's allowedCollections so a
  restricted user still sees what they can read.
- New renderM2ATemplate util resolves `{{collection}}` and
  `{{item:col.field}}` tokens against each junction row, sharing
  parseM2AToken with the query side so the two can't drift.
- Rows whose target collection is not readable show a block icon (only
  on genuine permission denial, not on a dangling FK).
- Add an in-body error state so a failed items request no longer leaves a
  blank body under a live pagination bar.
- isM2A helper plus M2A_TOKEN_RE/parseM2AToken/buildM2AFieldPath in
  displayHeuristics.
The system display-template picker can't introspect a polymorphic M2A
target, so adding a column display for an M2A field gave no hint about the
`item:<collection>.<field>` token syntax. Show a help icon and a short hint
(with the field's allowed collections) only for M2A fields.
- Add the Many-to-Any feature and a "Column Displays" usage section
  covering the `item:<collection>.<field>` template syntax.
- Fix factual drift verified against the code: layout name ("Super Table"),
  emitted events, layout-options block, composable names, project-structure
  tree, default page size, workflow list, repo URL and Node version.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

Quality Check Results

TypeScript Type Check

Passed - No type errors found

ESLint

Passed - No linting errors

Prettier Format Check

Passed - Code is properly formatted

Build

Passed - Extension builds successfully


Updated: 2026-06-01T08:57:02.589Z

@smartlabsAT smartlabsAT merged commit d6f73e7 into main Jun 1, 2026
22 checks passed
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.

M2A relationship is not displayed correctly

1 participant