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

[10.x] Illegal operator and value combination whereRelation with three parameters (where the value is <) #51033

Closed
siarheipashkevich opened this issue Apr 12, 2024 · 10 comments

Comments

@siarheipashkevich
Copy link
Contributor

siarheipashkevich commented Apr 12, 2024

Laravel Version

10.48.7

PHP Version

8.3.3

Database Driver & Version

MySQL 8.0.32

Description

I'm getting an error (Illegal operator and value combination) when use whereRelation with three parameters.

image

The interesting thing here is the $barcode variable contains the < character as value for searching.

But by the documentation if we are omitting the operator then the = will be used by default.

Steps To Reproduce

Call the method whereRelation with three parameters where value is <.

Product::query()->whereRelation('ingredients', 'barcode', '<')->get();
@siarheipashkevich siarheipashkevich changed the title 10.x Illegal operator and value combination whereRelation with three parameters (where the value is <) [10.x] Illegal operator and value combination whereRelation with three parameters (where the value is <) Apr 12, 2024
@driesvints
Copy link
Member

I think you forgot to provide the value for the fourth parameter? https://laravel.com/docs/11.x/eloquent-relationships#inline-relationship-existence-queries

Screenshot 2024-04-12 at 13 29 55

@siarheipashkevich
Copy link
Contributor Author

image

But above we have the example where we may omit the operator.

@driesvints
Copy link
Member

That's a boolean check, not a greater than comparison.

@siarheipashkevich
Copy link
Contributor Author

@driesvints do you mean that the three parameters can be used only with boolean values? It's very strange!

What about this?

Product::query()->where('barcode', '<')->get();

@driesvints
Copy link
Member

You're not comparing anything against. To what is it lower than? Can you please try passing the value you want to compare to?

@siarheipashkevich
Copy link
Contributor Author

@driesvints my search value is < as I described above.

< - is not the operator it's the value by which I want to find the product.

select * from products where barcode = '<';

Do you understand me?

@driesvints
Copy link
Member

Ah I finally see what you mean. Yeah unfortunately you'll have to try something like this:

Product::query()->whereRelation('ingredients', 'barcode', '=', '<')->get();

Does that work?

@siarheipashkevich
Copy link
Contributor Author

Yes I already fixed by this way, but it's not obvious. Maybe we need add some note to the documentation about this?

Do you think it's a problem or not?

@driesvints
Copy link
Member

I personally think it's pretty obvious, sorry. But you can always attempt to PR the docs. Thanks.

@siarheipashkevich
Copy link
Contributor Author

@driesvints thanks for you response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants