-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
Eloquent: firstWhere returns wrong result when passing an operator as value #41098
Comments
I think this is Postgres specific behavior? I get |
@driesvints It is still a Laravel bug though. Try something different (this one should work in MySQL too):
You are expecting it is looking for a user with name
When using
This one does the correct query:
Passing 2 arguments to a The query builder will always receive more than 2 arguments when it is called through framework/src/Illuminate/Database/Query/Builder.php Lines 706 to 708 in dbcb3a2
|
@marvinrabe I still get |
@driesvints Please note the assertion is different that time.
This |
Hah, I finally managed to reproduce that, thanks. |
The problem only occurs when the value (passing it as framework/src/Illuminate/Database/Query/Builder.php Lines 730 to 732 in dbcb3a2
|
This issue also effects passing enums to the
The above throws an error while validating
This would not happen when the default operator is correctly applied on Line 706 (Builder). |
@marvinrabe that seems more of a feature request to me. |
@driesvints It would be a feature request if I wanted to pass an enum as an operator. But in this case the Enum should be the value. But because of the error in the default handling it is not working correctly. This is an additional unwanted side effect of always passing more than 2 parameters from Please note that in this case everything works perfectly:
This error exists because of validating an operator, that should not be an operator in the first place. |
Description:
When calling the firstWhere() method of a Model with the second Parameter being "-" and when there is no database entry with "-" it returns a seemingly random Model object.
Probably it assumes "-" is the operator and value is "null". Which is not correct.
Steps To Reproduce:
Failing Test:
This test is using the User model. But every other model will do.
When explicitly specifying an operator it works as expected:
The text was updated successfully, but these errors were encountered: