Skip to content

fix(pinia-orm): scope decorator mutators, casts & hidden fields per entity#2027

Merged
CodeDredd merged 1 commit into
mainfrom
fix/per-entity-mutators-casts
Jul 19, 2026
Merged

fix(pinia-orm): scope decorator mutators, casts & hidden fields per entity#2027
CodeDredd merged 1 commit into
mainfrom
fix/per-entity-mutators-casts

Conversation

@CodeDredd

Copy link
Copy Markdown
Owner

Bug

fieldMutators, fieldCasts and the hidden array live as shared static objects on the base Model class. setMutator(), setCast() and setHidden() (used by the @Mutate, @Cast and @Hidden decorators) wrote into these shared objects keyed only by field name — so a mutator/cast/hidden registered for one entity leaked to every other entity with a same-named field.

Fix

Key fieldMutators and fieldCasts by modelEntity() — the same pattern schemas, registries and fieldsOnDelete already use. setHidden() now does copy-on-write so it no longer pushes into the base class' shared array.

Tests

4 new regression tests (mutator decorator, setMutator, cast decorator, hidden decorator across two entities with same-named fields). All fail before the fix, pass after; full suite green (401 tests).

fixes #1937
fixes #1992

…ntity

Mutators, casts and hidden fields registered via setMutator/setCast/
setHidden (and thus via the Mutate, Cast and Hidden decorators) were
stored on shared static objects of the base Model class, keyed only by
field name. A mutation registered for one entity was therefore applied
to every entity that has a field with the same name.

They are now keyed by entity, like the schema registries already are.

fixes #1937
fixes #1992
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2027      +/-   ##
==========================================
+ Coverage   99.43%   99.50%   +0.06%     
==========================================
  Files          82       82              
  Lines        3019     3022       +3     
  Branches      529      530       +1     
==========================================
+ Hits         3002     3007       +5     
+ Misses         14       12       -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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants