feat(pinia-orm): fire lifecycle hooks in fresh()#2036
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Feature (#1722)
fresh()silently skipped all lifecycle hooks, which surprised several users using hooks to normalize backend data.fresh()now firessaving/creatingbefore andsaved/createdafter persisting, per record.falseexcludes that record from the replacement.save()).fresh(records, { raw: true })restores the old no-hooks behavior — the opt-out flag suggested in the issue discussion.insert/flushdon'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,
falseveto skips the record,{ raw: true }fires nothing. Full suite green (413 tests).closes #1722