Skip to content

feat(pinia-orm): fire lifecycle hooks in fresh()#2036

Merged
CodeDredd merged 1 commit into
mainfrom
feat/fresh-lifecycle-hooks
Jul 20, 2026
Merged

feat(pinia-orm): fire lifecycle hooks in fresh()#2036
CodeDredd merged 1 commit into
mainfrom
feat/fresh-lifecycle-hooks

Conversation

@CodeDredd

Copy link
Copy Markdown
Owner

Feature (#1722)

fresh() silently skipped all lifecycle hooks, which surprised several users using hooks to normalize backend data.

  • fresh() now fires saving/creating before and saved/created after persisting, per record.
  • A before hook returning false excludes that record from the replacement.
  • Hooks can mutate the model (same as save()).
  • fresh(records, { raw: true }) restores the old no-hooks behavior — the opt-out flag suggested in the issue discussion.
  • Docs: lifecycle-hooks page now states which methods fire hooks (and that insert/flush don't — the undocumented gotcha called out in the issue), inserting-data page documents { raw: true }.

Behavior change (hooks now fire by default) — intended for v2.

Tests

4 new tests: hooks fire per record, hook mutation lands in the store, false veto skips the record, { raw: true } fires nothing. Full suite green (413 tests).

closes #1722

fresh() now fires the saving/creating and saved/created hooks for every
record. Records for which a before hook returns false are not
persisted. Passing { raw: true } as second argument restores the old
behaviour and persists the data without firing any hooks.

closes #1722
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.40%. Comparing base (c6bebb9) to head (886d251).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2036   +/-   ##
=======================================
  Coverage   99.40%   99.40%           
=======================================
  Files          82       82           
  Lines        3025     3043   +18     
  Branches      533      540    +7     
=======================================
+ Hits         3007     3025   +18     
  Misses         15       15           
  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 e752764 into main Jul 20, 2026
12 of 13 checks passed
@CodeDredd
CodeDredd deleted the feat/fresh-lifecycle-hooks 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.

fresh() doesn't call any lifecycle Hook

2 participants