Skip to content

Conversation

@abnegate
Copy link
Member

@abnegate abnegate commented Oct 1, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Resolved inconsistent results when querying nested relationships by isolating per-relationship query state, ensuring reliable data across multi-document queries and after batch create/delete operations.
    • Improves stability when fetching related documents (e.g., parent/child chains), preventing cross-record contamination.
  • Tests

    • Added end-to-end coverage for multi-document queries with nested relationships, including validation after re-creation of documents, to ensure consistent results and relationship integrity.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 1, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Introduces cloning of per-relationship Query selections in Database population logic to prevent mutation side effects. Adds an end-to-end test covering multi-document queries with nested relationships (car → customer → inspections), including assertions before and after batch re-creation of documents, and cleanup.

Changes

Cohort / File(s) Summary
Relationship query cloning
src/Database/Database.php
Clone each per-relationship Query from selection map before use during relationship population to avoid mutating shared Query instances.
E2E tests for nested relationships
tests/e2e/Adapter/Scopes/RelationshipTests.php
Add testMultiDocumentNestedRelationships validating nested relationship selections across multi-document queries and after batch re-create operations; includes setup, assertions, and cleanup.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Client
  participant DB as Database
  participant RP as Relationship Population

  Client->>DB: find(car, selects: customer, customer.inspections.type)
  DB->>RP: populateDocumentRelationships(docs, selects)
  note over RP: For each relationship key<br/>clone Query selections
  RP->>RP: For each doc: apply cloned queries
  RP->>DB: fetch related customer
  RP->>DB: fetch related inspections (nested)
  DB-->>RP: related records
  RP-->>DB: docs with populated relations
  DB-->>Client: result set
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • fogelito

Poem

I hop through docs, relations in a row,
Cloning little queries so side effects won’t grow.
Cars meet their drivers, inspections tagged just right—
Nested paths unruffled, all tidy and light.
Thump-thump, merge drum—tests pass, let’s go! 🐇✨

✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-nested-selection

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 398b5d5 and 7ec0238.

📒 Files selected for processing (2)
  • src/Database/Database.php (1 hunks)
  • tests/e2e/Adapter/Scopes/RelationshipTests.php (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@abnegate abnegate marked this pull request as ready for review October 1, 2025 03:59
@abnegate abnegate merged commit eaffdc1 into main Oct 1, 2025
14 of 15 checks passed
@abnegate abnegate deleted the fix-nested-selection branch October 1, 2025 04:00
@coderabbitai coderabbitai bot mentioned this pull request Dec 3, 2025
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.

2 participants