Add Many-to-Any (M2A) field support (#60)#62
Merged
Conversation
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.
Quality Check ResultsTypeScript 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
expandTokensThroughRelationnow handles M2A: it emits thecollectiondiscriminator plus per-collectionitem:<collection>.<field>paths and drops bare/disallowed tokens, so the items request can no longer 403.resolveM2ARelationutil centralises the junction-shape lookup (discriminator, item field, allowed collections).renderM2ATemplateutil resolves{{collection}}and{{item:col.field}}tokens per junction row, sharingparseM2ATokenwith the query side so the two cannot drift.Permissions
blockicon — only on genuine permission denial, not on a dangling FK.resolveM2ARelationfalls back tojunction_field+ the field'sallowedCollectionswhen Directus filters the polymorphic relation out, so a restricted user still sees what they can read.Robustness & UX
Docs
Out of scope
Inline editing of relational fields (M2O/O2M/M2M/M2A) — tracked in #61. Relational fields remain display-only by design.
Testing
pnpm run test);pnpm run qualitygreen.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.