fix: [#738] The Orm Creating event can be triggered when the query with the Model method#1167
fix: [#738] The Orm Creating event can be triggered when the query with the Model method#1167
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1167 +/- ##
==========================================
- Coverage 68.61% 68.60% -0.02%
==========================================
Files 223 223
Lines 14480 14475 -5
==========================================
- Hits 9936 9930 -6
- Misses 4168 4169 +1
Partials 376 376 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an issue where ORM creating events were being incorrectly triggered when using Model methods with slice data or mass operations. The fix ensures that model events are only triggered for single record operations, not for batch operations or slice data.
- Added checks to prevent event triggering for slice data in create, save, update, delete, and retrieve operations
- Refactored error handling throughout the codebase to use a new
errors.Ignore()utility function - Added comprehensive test coverage for the event triggering behavior with slice data and mass operations
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| database/gorm/query.go | Added slice and ID validation to prevent inappropriate event triggering |
| errors/errors.go | Added new Ignore() utility function for simplified error handling |
| tests/query_test.go | Added test cases to verify events are not triggered for slice operations |
| tests/models.go | Added panic conditions to catch incorrect event triggering scenarios |
| Multiple files | Refactored defer statements to use errors.Ignore() for cleaner error handling |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
📑 Description
Closes goravel/goravel#738
✅ Checks