Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] whereDoesntHave not taking optional nested relations into account #24023

Closed
bertheyman opened this issue Apr 26, 2018 · 3 comments
Closed

Comments

@bertheyman
Copy link

  • Laravel Version: 5.5.39
  • PHP Version: 7.1.1

Description:

Example: every book belongs to an optional subcategory, in turn belonging to a regular category.
We're trying to use the querybuilder to exclude books belonging to a category meeting certain conditions. (e.g. set to invisible)

$builder->whereDoesntHave('subcategory.category', function ($query) {
    $query->where('visible', 0);
})

The above example would not return a book without a subcategory.
However, this book doesn't have a related category set to visible = 0, so one would expect this book to turn up in the results.

I'm not sure if this is intended this way, but it sure confused me for some time. So either a fix, or a warning in the docs might be useful.

Steps To Reproduce:

Test the above query.
To work correctly, the model would need a corresponding subcategory.

*Please note: this is my first issue in the Laravel repo. Feedback is welcomed.

@staudenmeir
Copy link
Contributor

staudenmeir commented Apr 29, 2018

I can see why you would expect a different behavior, but I don't think this will be changed. It would potentially break people's existing code and probably wouldn't be an easy fix.

@bertheyman
Copy link
Author

Thanks for the feedback! Will give it a try.

@staudenmeir
Copy link
Contributor

You were absolutely right, this is a bug. It will be fixed in the next release: #26228

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

No branches or pull requests

2 participants