Skip to content

Add single-collection inheritance for documents - #15

Merged
DavidBadura merged 1 commit into
1.1.xfrom
inheritance
Aug 31, 2026
Merged

Add single-collection inheritance for documents#15
DavidBadura merged 1 commit into
1.1.xfrom
inheritance

Conversation

@DavidBadura

@DavidBadura DavidBadura commented Aug 31, 2026

Copy link
Copy Markdown
Member

Document classes can now form a hierarchy that shares one collection. The root carries a #[DiscriminatorMap] attribute mapping a stable string to each concrete class; subclasses inherit the collection, database, id property and indexes. Every stored document gets a discriminator field (_type by default) so the hydrator can reconstruct the concrete class on load.

The repository for the root class is polymorphic: it accepts any subclass on write and returns concrete types on read. A repository for a concrete class is scoped to its own discriminator value, so its queries, counts and deletes never touch sibling types, and writes reject foreign types with WrongClass.

The metadata factory walks the parent chain to find the #[Document] class, validates the map and merges the field mappings of the whole hierarchy so you can filter by inherited and subclass-only properties from the root. Conflicting field names across subclasses raise DiscriminatorFieldConflict.

@DavidBadura DavidBadura added this to the 1.1.0 milestone Aug 31, 2026
@DavidBadura DavidBadura added the enhancement New feature or request label Aug 31, 2026
@DavidBadura
DavidBadura merged commit 7ac4c59 into 1.1.x Aug 31, 2026
18 of 20 checks passed
@DavidBadura
DavidBadura deleted the inheritance branch August 31, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants