Skip to content

Adopt pure entity trees#109

Merged
alganet merged 1 commit intoRespect:masterfrom
alganet:pk-track
Mar 26, 2026
Merged

Adopt pure entity trees#109
alganet merged 1 commit intoRespect:masterfrom
alganet:pk-track

Conversation

@alganet
Copy link
Copy Markdown
Member

@alganet alganet commented Mar 26, 2026

  • Mapper::flush() resets pending queue on failure, preventing cascading errors across requests in long-running runtimes (Swoole, ReactPHP)
  • Db::executeStatement() resets SQL state before execute, not after, so failures don't corrupt subsequent queries
  • extractAndOperateCompositions() converts spec keys via Style::realProperty() to match DB column names after extractColumns() conversion
  • Composite joins now emit explicit ON clauses instead of relying on implicit FK inference
  • Composite entities no longer carry child PKs (commentId removed)
  • checkNewIdentity() casts lastInsertId to int for typed properties
  • Removed unused $parentCols parameter from insertCompositionChildren()
  • All test stubs use typed properties and pure entity tree pattern

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 26, 2026

Codecov Report

❌ Patch coverage is 98.14815% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.68%. Comparing base (f0f0ba4) to head (686d92a).

Files with missing lines Patch % Lines
src/Mapper.php 98.03% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #109      +/-   ##
============================================
+ Coverage     98.32%   98.68%   +0.35%     
- Complexity      172      182      +10     
============================================
  Files             4        4              
  Lines           419      456      +37     
============================================
+ Hits            412      450      +38     
+ Misses            7        6       -1     

☔ 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.

Copy link
Copy Markdown

Copilot AI left a comment

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 updates the ORM mapping behavior to support “pure entity tree” relationships (object references instead of FK scalar fields) and hardens runtime safety by ensuring internal mapper/DB state is reset after failures—important for long-running PHP runtimes (e.g., Swoole/ReactPHP).

Changes:

  • Reset Mapper pending state on flush() failure; reset Db SQL state before executing statements.
  • Rework composite handling: DB-column name normalization, explicit JOIN ... ON ... clauses, and composition child INSERT/UPDATE behavior.
  • Update test stubs and mapper tests to use typed properties and pure entity tree relations (no embedded child PK fields).

Reviewed changes

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

Show a summary per file
File Description
src/Mapper.php Adds reset-on-failure for flush(), reworks composite extraction/update, adds composition child inserts, normalizes extracted column keys, and adds explicit composite join ON clauses.
src/Db.php Resets SQL builder state before statement execution to prevent cross-query contamination after failures.
tests/MapperTest.php Adds/updates tests for pending reset, composite collision precedence, skipping cascades for uninitialized relations, and updated “id not initialized” assertions.
tests/Stubs/Postcomment.php Converts stub to typed properties and pure entity tree relation (Author $author).
tests/Stubs/PostCategory.php Converts to typed entity relations (Post $post, Category $category) instead of FK scalar fields.
tests/Stubs/Post.php Converts to typed properties and replaces comment_id with Comment $comment.
tests/Stubs/OtherEntity/Post.php Tightens typing and removes FK scalar handling in favor of Author $author.
tests/Stubs/OtherEntity/Comment.php Converts FK scalar to relation (Post $post) and tightens typing.
tests/Stubs/OtherEntity/Author.php Tightens typing for id/name accessors.
tests/Stubs/Issues.php Changes id to typed int.
tests/Stubs/Issue.php Changes id to typed int.
tests/Stubs/Improvement.php Changes id to typed int.
tests/Stubs/Comment.php Converts post to typed Post relation and tightens typing.
tests/Stubs/Category.php Converts to typed properties and replaces category_id with Category $category relation.
tests/Stubs/Bug.php Changes id to typed int.
tests/Stubs/Author.php Changes id/name to typed non-nullable properties.

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

- Mapper::flush() resets pending queue on failure, preventing cascading
  errors across requests in long-running runtimes (Swoole, ReactPHP)
- Db::executeStatement() resets SQL state before execute, not after,
  so failures don't corrupt subsequent queries
- extractAndOperateCompositions() converts spec keys via Style::realProperty()
  to match DB column names after extractColumns() conversion
- Composite joins now emit explicit ON clauses instead of relying on
  implicit FK inference
- Composite entities no longer carry child PKs (commentId removed)
- checkNewIdentity() casts lastInsertId to int for typed properties
- Removed unused $parentCols parameter from insertCompositionChildren()
- All test stubs use typed properties and pure entity tree pattern
@alganet alganet marked this pull request as ready for review March 26, 2026 21:44
@alganet alganet merged commit 61bd2da into Respect:master Mar 26, 2026
3 checks passed
@alganet alganet deleted the pk-track branch March 26, 2026 21:44
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