Skip to content

feat(pinia-orm): hydrate recursively discriminated models#2037

Merged
CodeDredd merged 2 commits into
mainfrom
feat/recursive-sti-hydration
Jul 20, 2026
Merged

feat(pinia-orm): hydrate recursively discriminated models#2037
CodeDredd merged 2 commits into
mainfrom
feat/recursive-sti-hydration

Conversation

@CodeDredd

@CodeDredd CodeDredd commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Feature (#1995)

STI only resolved one discriminator level: a record for Document -> File -> Video was hydrated as File, never as Video.

  • New Model#$getDiscriminatedModel(record) walks nested type keys (each level may define its own typeKey + types()) and returns the most specific matching model. Cycle-safe via a visited set (the self-referencing entries in inherited types() maps terminate the walk).
  • Query#getHydratedModel() (find/all/save hydration) and Repository#make() both use it — make() previously did no type resolution at all.
  • useRepo() now registers nested type models to the database recursively, so saving into deep hierarchies resolves their entities.
  • Docs: new Nested Discriminators section on the STI page.

Tests

New STI test with a 3-level hierarchy (Animal -> Dog -> Terrier, second discriminator race): make() resolves to the deepest type incl. its fields, intermediate and base types still resolve correctly, and find() after save() returns the specific type. Full suite green (406 tests).

closes #1995

Discriminated models can now be nested over multiple levels (e.g.
Document -> File -> Video). When hydrating a record, the type keys are
walked down the hierarchy and an instance of the most specific matching
type is created. make() now also resolves discriminated types, and
nested type models are registered to the database.

closes #1995
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.47%. Comparing base (c6bebb9) to head (86a6a80).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2037      +/-   ##
==========================================
+ Coverage   99.40%   99.47%   +0.06%     
==========================================
  Files          82       82              
  Lines        3025     3046      +21     
  Branches      533      538       +5     
==========================================
+ Hits         3007     3030      +23     
+ Misses         15       13       -2     
  Partials        3        3              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@CodeDredd
CodeDredd merged commit 3ebc920 into main Jul 20, 2026
13 checks passed
@CodeDredd
CodeDredd deleted the feat/recursive-sti-hydration branch July 20, 2026 15:06
@github-actions github-actions Bot mentioned this pull request Jul 20, 2026
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.

Support for Recursive Discriminated Models

2 participants