feat: add query relation#1463
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1463 +/- ##
==========================================
- Coverage 69.19% 68.52% -0.67%
==========================================
Files 370 385 +15
Lines 29338 32482 +3144
==========================================
+ Hits 20300 22259 +1959
- Misses 8106 9141 +1035
- Partials 932 1082 +150 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Introduce contracts and regenerate mocks for the unified relation rework: Relation/RelationWriter/PivotQuery, ModelWithRelations, RelationCallback/MorphRelationCallback/PivotCallback. Add the corresponding OrmRelation* / OrmEagerLoad* errors and remove the obsolete Association contract. (cherry picked from commit 1a39fa5)
Introduce a morph map under database/orm/morphmap to register and resolve polymorphic class aliases, plus the contracts/database/orm/morph.go and database/orm/morph.go entry points used by relation queries to translate between *_type column values and registered model types. (cherry picked from commit 06b7cb8)
Replace the old Preload-based With() pipeline with an eager-load engine that parses dotted paths, batches per-relation queries, and hydrates results back onto the parent model. Add OfMany / LatestOfMany / OldestOfMany aggregate selectors usable inside With() callbacks. Update Cursor() to run eager loads per-row and Load() to forward variadic args to With(). (cherry picked from commit 65dedf6)
Add the read-side relation engine: relation.go resolves Relations() definitions into typed Has-One/Has-Many/Belongs-To/MorphMany/etc. relations with shared key inference; new_relation.go exposes the Related() helper for ad-hoc relation queries; queries_relationships.go provides Has, OrHas, DoesntHave, HasMorph and WhereRelation existence/absence builders driven by Conditions.relations. (cherry picked from commit 611d2ca)
Add the relation write API (Save/Push/Associate/Dissociate/Attach/Detach/Sync/ Toggle) implemented over the unified relation resolver, plus a PivotQuery builder for filtering and updating pivot rows including pivot-defined created_at/updated_at columns. Introduce contracts.db.SyncResult to report attached/detached/updated ids per Sync call. (cherry picked from commit ee0fcde)
…ework Add tests covering With/Has/HasMorph/Load/PivotQuery/Sync flows against the real database drivers, refresh tests/mock_config.go and tests go.mod/go.sum for the new dependencies, and document the many-to-many API in docs/orm-many-to-many.md. (cherry picked from commit 185c0a8)
(cherry picked from commit 9f6456e)
f5a4bed to
da8db93
Compare
|
Hey @LinboLen Is the PR ready to be reviewed, please? And FYI, CI failed. |
|
is tested pass on my local dev environment. currently is finished state. I will fix the ci failed. this pr not use gorm associate any more. use |
Remove GORM relation tags from test model struct fields and implement Relations() methods instead. This aligns with the new relation system that forbids GORM tags and requires explicit relation declarations. Changes: - Add `gorm:"-"` tags to all relation fields - Implement Relations() for User, Role, Address, and Book models - Use contractsorm relation types (HasOne, HasMany, BelongsTo, Many2Many, MorphOne, MorphMany) Fixes CI test failures in TestWithSuite.
|
fixed all test case. and removed association code in query. the codecov is low. adding more test case |
a2128fa to
c01e6cf
Compare
c01e6cf to
eda8bab
Compare
|
some of api are real database read and write. already covered in another test case. so the codecov is down for now and can't add this coverage test |
📑 Description
Closes goravel/goravel#963
✅ Checks