Skip to content

Refactor diff detection for direct relations - #27

Merged
thijskok merged 1 commit into
mainfrom
fix-direct-relation-diff-changed-detection
Jul 22, 2026
Merged

Refactor diff detection for direct relations#27
thijskok merged 1 commit into
mainfrom
fix-direct-relation-diff-changed-detection

Conversation

@thijskok

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread src/Diff.php
*/
protected function diffPivotedRelation(array $before, array $after, string $relatedKey): array
{
$beforeIds = array_column($before['pivots']['items'] ?? [], $relatedKey);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved this code to a helper below

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Refactors relation diffing in Diff to share logic between pivoted and direct relations, and expands direct-relation diffs to report per-record field changes (not just added/removed), aligning behavior with pivoted relation diffs.

Changes:

  • Extracted shared relation-item diff logic into Diff::diffItemsByKey() and reused it for both pivoted and direct relations.
  • Updated direct relation diffing to populate the changed bucket for existing related records whose fields changed.
  • Added a regression test ensuring direct-relation record changes are surfaced via Diff::changes().

Reviewed changes

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

File Description
tests/RevisionDiffTest.php Adds coverage to assert that updates to an existing direct-related record appear under changed.
src/Diff.php Refactors and unifies relation diffing; enables column-level change detection for direct relations via a shared helper.

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

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@thijskok
thijskok requested a review from Frankisgek July 21, 2026 19:39
@thijskok
thijskok merged commit 2ca0c40 into main Jul 22, 2026
7 checks passed
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.

4 participants