Skip to content

test: compare whereHas through constraints - #327

Open
elpete wants to merge 1 commit into
nextfrom
test/116-where-has-through-constraints
Open

test: compare whereHas through constraints#327
elpete wants to merge 1 commit into
nextfrom
test/116-where-has-through-constraints

Conversation

@elpete

@elpete elpete commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

Closes #116

Review

This is a core correctness issue for Quick. A composed hasManyThrough relationship must apply the same intermediate and callback constraints as the equivalent expanded relationship path.

Recommendation: 10/10.

Reasons for

  • whereHas is commonly used for authorization and filtering, so over-inclusive results are dangerous.
  • A named through relationship should be semantically equivalent to its expanded path.
  • The regression can be asserted through the public query API with deterministic fixture data.

Reasons against

  • Through relationship SQL is complex and fixes can affect eager loading, nested constraints, and aliases, so broad regression testing is necessary.

Attempted reproduction

I compared Country.whereHas( "posts", callback ), where posts is hasManyThrough([ "users", "posts" ]), with Country.whereHas( "users.posts", callback ). Both callbacks constrain the terminal post to post_pk = 321.

The issue no longer reproduces on current next with qb@14.0.0-beta.3: both forms return only Argentina. The relevant historical fixes include correcting through-constraint application and removing an extra join from has/whereHas that pulled back too many rows. This PR preserves exact equivalence coverage.

Validation

  • Focused querying-relationships spec: 38 passed, 0 failed, 0 errors
  • Full suite: 496 passed, 0 failed, 0 errors, 3 skipped
  • Formatter completed
  • git diff --check 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.

1 participant