Skip to content

doc: document @@delegateMap attribute#607

Merged
ymc9 merged 3 commits into
mainfrom
doc/delegate-map-attribute
May 24, 2026
Merged

doc: document @@delegateMap attribute#607
ymc9 merged 3 commits into
mainfrom
doc/delegate-map-attribute

Conversation

@ymc9
Copy link
Copy Markdown
Member

@ymc9 ymc9 commented May 24, 2026

Summary

  • Document the new @@delegateMap attribute (introduced in zenstack v3.7.1 via zenstackhq/zenstack#2676) for customizing the discriminator value of polymorphic sub-models.
  • Add a "Customizing the discriminator value" section to docs/orm/polymorphism.md covering the default behavior, string-discriminator and enum-discriminator usage, TS narrowing, and validation rules. Marked <AvailableSince version="v3.7.1" />.
  • Add a reference entry for @@delegateMap next to @@delegate in docs/reference/zmodel/attribute.md.

Test plan

  • pnpm start and verify the new section renders correctly on /docs/orm/polymorphism
  • Verify the new reference entry renders on /docs/reference/zmodel/attribute and that the cross-link to the ORM section works
  • pnpm build completes without errors

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation
    • Added comprehensive guide on customizing discriminator values in polymorphism, including examples for String and enum field types.
    • Documented the @@delegateMap attribute, explaining how to override default discriminator value mappings in delegate models.

Review Change Stack

… discriminator value

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
zenstack-new-site Ready Ready Preview, Comment May 24, 2026 1:51am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 24, 2026

Warning

Review limit reached

@ymc9, we couldn't start this review because you've used your available PR reviews for now.

Your plan currently allows 1 review/hour. Refill in 52 minutes and 17 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 07f8f2ce-5dbb-4bfc-aed6-82502044905c

📥 Commits

Reviewing files that changed from the base of the PR and between df1ba8b and ff88c96.

📒 Files selected for processing (1)
  • docs/orm/polymorphism.md

Walkthrough

This PR adds documentation for a new @@delegateMap attribute that enables customization of discriminator values in polymorphic ORM models. It includes canonical reference documentation of the attribute and practical examples demonstrating its usage with both string and enum discriminator fields.

Changes

Polymorphic Model Discriminator Customization Documentation

Layer / File(s) Summary
Reference documentation for @@delegateMap attribute
docs/reference/zmodel/attribute.md
Documented the new predefined model attribute @@delegateMap with its syntax, value: Any parameter, and explanation of how it maps delegate sub-models to discriminator values.
Polymorphism guide with discriminator customization examples
docs/orm/polymorphism.md
Added a new "Customizing the discriminator value" subsection (marked as AvailableSince v3.7.1) with examples showing how to override default discriminator values using @@delegateMap for both String and enum discriminator field types.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: documentation for the @@delegateMap attribute. It is concise, specific, and directly relates to all changes in the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch doc/delegate-map-attribute

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
docs/orm/polymorphism.md (1)

73-100: ⚡ Quick win

Consider clarifying that @@delegateMap relaxes the enum-value-must-match-model-name constraint.

The example demonstrates that enum values (e.g., ASSET_KIND_VIDEO) don't need to match model names (e.g., Video), but this isn't explicitly stated. In v2.x documentation, it was noted that "enum fields must match the concrete model names" when using @@delegate. Since @@delegateMap removes this restriction, adding a brief note would help users understand the key benefit.

📝 Suggested clarification

Add a note before or within the enum discriminator subsection:

When the discriminator field is an enum, pass an enum member to `@@delegateMap`. The member must come from the same enum as the discriminator field. Unlike the default behavior where enum values must match concrete model names, `@@delegateMap` allows you to use any enum value:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/orm/polymorphism.md` around lines 73 - 100, Add a short explicit note in
the "Enum discriminator" section clarifying that @@delegateMap relaxes the
enum-value-must-match-model-name constraint: mention that when using
@@delegateMap you can map any enum member from the same enum (e.g., AssetKind)
to a concrete model (e.g., Video, Image) even when the enum value
(ASSET_KIND_VIDEO) does not equal the model name (Video), and place this
sentence near the existing explanation that references @@delegateMap, AssetKind,
Asset, Video, and Image.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/orm/polymorphism.md`:
- Around line 30-46: The discriminator section describing default behavior for
Content.type and the @@delegate usage is missing guidance on TypeScript
narrowing and validation rules; update the polymorphism.md discriminator
subsection to either (1) add concise instructions showing how to leverage the
discriminator (e.g., Content.type = "Video"/"Image") for TypeScript narrowing in
code examples and how to enforce/validate allowed discriminator values at model
boundaries, or (2) add a clear cross-reference/link to the dedicated “TypeScript
narrowing” and “validation rules” section; ensure you mention the concrete model
names (Video, Image), the base field (Content.type), and the
@@delegate/@@delegateMap usage so readers can find the relevant examples.

---

Nitpick comments:
In `@docs/orm/polymorphism.md`:
- Around line 73-100: Add a short explicit note in the "Enum discriminator"
section clarifying that @@delegateMap relaxes the
enum-value-must-match-model-name constraint: mention that when using
@@delegateMap you can map any enum member from the same enum (e.g., AssetKind)
to a concrete model (e.g., Video, Image) even when the enum value
(ASSET_KIND_VIDEO) does not equal the model name (Video), and place this
sentence near the existing explanation that references @@delegateMap, AssetKind,
Asset, Video, and Image.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 04493592-9fd5-4182-918a-451f19dfb2d6

📥 Commits

Reviewing files that changed from the base of the PR and between 7cea12b and df1ba8b.

📒 Files selected for processing (2)
  • docs/orm/polymorphism.md
  • docs/reference/zmodel/attribute.md

Comment thread docs/orm/polymorphism.md
…elegateMap docs

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@ymc9 ymc9 merged commit 78359db into main May 24, 2026
4 checks passed
@ymc9 ymc9 deleted the doc/delegate-map-attribute branch May 24, 2026 01:51
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.

1 participant