-
-
Notifications
You must be signed in to change notification settings - Fork 133
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
WhereHas Constraints Not Working #118
Comments
@MannikJ Which version of the package are you using? |
Sorry, v2.1 it was, I guess Update: Just updated to the latest v2.1.1 but the issue is still there.. @topclaudy Do you have an idea? |
Sorry for the delay. Can you try 2.0.x? |
I am facing the same problem. |
And as was also in the original authors code snippet. I too am trying to have a relationship onto the same class. So: class A extends Model
{
use compoships;
public function linkedA()
{
return $this->belongsTo(
A::class,
['linked_a_id', 'other_id'],
['id', 'other_id']
);
}
}
A::whereHas('linkedA'); does not work. If we add class B extends Model
{
use compoships;
public function a()
{
return $this->belongsTo(
B::class,
['a_id', 'other_id'],
['id', 'other_id']
);
}
}
B::whereHas('a'); it works. |
I can confirm I have the same setup as TheFehr and the issue only presents when the relation is on the same model e.g. a parent/child relationship. |
As this was a big problem for me I removed this package and added calculated id columns for the pair of id's I needed to match. For anyone curious I used the cantor pairing function. If you use this approach don't forget to always use the same order for your two id's otherwise it won't work. And don't forget to add indexes for the new calculated id column. |
I have the following setup in my app:
When I try use the relation inside whereHas, I get an exception:
The problem here is that the generated SQL is wrong, because obviously there are no columns
0
and1
. But I have no clue where it comes from. And I am quite sure that a query like this has once worked.If I query the relations via a job instance like below, there is no exception because the resulting SQL is correct:
The text was updated successfully, but these errors were encountered: