Skip to content

feat(model): add polymorphic association support#2104

Merged
bpamiri merged 1 commit intodevelopfrom
peter/polymorphic-associations
Apr 15, 2026
Merged

feat(model): add polymorphic association support#2104
bpamiri merged 1 commit intodevelopfrom
peter/polymorphic-associations

Conversation

@bpamiri
Copy link
Copy Markdown
Collaborator

@bpamiri bpamiri commented Apr 15, 2026

Summary

  • Adds Rails-style polymorphic associations (belongsTo(polymorphic=true), hasMany(as=...), hasOne(as=...))
  • Polymorphic belongsTo resolves target model dynamically from the type column; eager loading via include= throws Wheels.PolymorphicIncludeNotSupported
  • hasMany/hasOne with as adds type discriminator to JOIN ON clauses and dynamic method WHERE clauses, and auto-sets the type column on new/create operations

Test plan

  • 15 BDD specs covering metadata storage, dynamic resolution, type discrimination, foreign key conventions, and error handling
  • All 2764 existing tests still pass (6 pre-existing failures unrelated to this change)
  • CI matrix: verify across Lucee 5/6/7, Adobe 2021/2023/2025, BoxLang

🤖 Generated with Claude Code

Adds Rails-style polymorphic associations to the Wheels ORM:
- belongsTo(name="commentable", polymorphic=true) for the child side
- hasMany(name="comments", as="commentable") for the parent side
- hasOne(name="comment", as="commentable") for singular parent side

Polymorphic belongsTo resolves the target model dynamically from the
type column at runtime. Eager loading via include= throws a clear error
since the target model varies per row. hasMany/hasOne with as= adds a
type discriminator to both JOIN ON clauses and dynamic method WHERE
clauses, and auto-sets the type column on new/create operations.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bpamiri bpamiri force-pushed the peter/polymorphic-associations branch from af30a41 to f060287 Compare April 15, 2026 06:02
@bpamiri bpamiri merged commit bc2c4c2 into develop Apr 15, 2026
3 checks passed
@bpamiri bpamiri deleted the peter/polymorphic-associations branch April 15, 2026 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant