Skip to content

Extract hydration from Relational into AbstractMapper - #14

Merged
alganet merged 1 commit into
Respect:masterfrom
alganet:hydration
Mar 19, 2026
Merged

Extract hydration from Relational into AbstractMapper#14
alganet merged 1 commit into
Respect:masterfrom
alganet:hydration

Conversation

@alganet

@alganet alganet commented Mar 18, 2026

Copy link
Copy Markdown
Member
  • Add resolveEntityName() to Collection with polymorphic override in Typed that reads the discriminator column via EntityFactory
  • Move Filtered persist delegation to AbstractMapper::persist(), so any backend routes filtered collections to their parent automatically
  • Move postHydrate()/tryHydration() to AbstractMapper as protected methods for FK-to-object wiring using Style naming conventions
  • Move buildEntitiesInstances() to AbstractMapper for collection-tree entity creation with Filtered skip and Composite duplication
  • Rewrite InMemoryMapper to use shared postHydrate() instead of custom resolveRelations(), proving the abstraction works outside SQL
  • InMemoryMapper now supports Typed collections via resolveEntityName()
  • Remove unnecessary local variable aliases for $this->entityFactory

@alganet
alganet requested a review from Copilot March 18, 2026 23:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors entity hydration and related-entity wiring into AbstractMapper, adds a per-row entity-name resolution hook on Collection (with a polymorphic override in Typed), and updates the in-memory test mapper to consume the shared hydration logic.

Changes:

  • Add Collection::resolveEntityName() and override it in Collections\Typed using a discriminator column read via EntityFactory.
  • Move hydration wiring logic into AbstractMapper (postHydrate() / tryHydration()) and update InMemoryMapper to use it.
  • Add Filtered persist delegation in AbstractMapper::persist() and introduce buildEntitiesInstances() as a shared helper.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
tests/InMemoryMapper.php Refactors relation fetching to build an entity graph + call shared postHydrate(), and uses resolveEntityName() for Typed collections.
src/Collections/Typed.php Implements discriminator-based entity resolution via resolveEntityName().
src/Collections/Collection.php Introduces the resolveEntityName() extension point on all collections.
src/AbstractMapper.php Adds Filtered persist routing, shared hydration wiring helpers, and shared entity-instance building helper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/AbstractMapper.php Outdated
Comment thread src/AbstractMapper.php
Comment thread src/AbstractMapper.php
Comment thread src/Collections/Typed.php
- Add resolveEntityName() to Collection with polymorphic override in
  Typed that reads the discriminator column via EntityFactory
- Move Filtered persist delegation to AbstractMapper::persist(), so any
  backend routes filtered collections to their parent automatically
- Move postHydrate()/tryHydration() to AbstractMapper as protected
  methods for FK-to-object wiring using Style naming conventions
- Move buildEntitiesInstances() to AbstractMapper for collection-tree
  entity creation with Filtered skip and Composite duplication
- Rewrite InMemoryMapper to use shared postHydrate() instead of custom
  resolveRelations(), proving the abstraction works outside SQL
- InMemoryMapper now supports Typed collections via resolveEntityName()
- Remove unnecessary local variable aliases for $this->entityFactory
@alganet
alganet marked this pull request as ready for review March 19, 2026 00:29
@alganet
alganet merged commit 3f39ede into Respect:master Mar 19, 2026
3 checks passed
@alganet
alganet deleted the hydration branch March 19, 2026 00:29
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 61.53846% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.13%. Comparing base (f86f395) to head (b8b3f69).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/AbstractMapper.php 61.76% 13 Missing ⚠️
src/Collections/Collection.php 0.00% 2 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##              master      #14      +/-   ##
=============================================
- Coverage     100.00%   96.13%   -3.87%     
- Complexity       138      157      +19     
=============================================
  Files             13       13              
  Lines            349      388      +39     
=============================================
+ Hits             349      373      +24     
- Misses             0       15      +15     

☔ View full report in Codecov by Sentry.
📢 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.

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.

3 participants