-
-
Notifications
You must be signed in to change notification settings - Fork 854
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
Can't use column searches in same table relations #2871
Comments
@affaron thank you for investigating. This is currently a package limitation and doesn't work yet with a self-join relationship. If you can add a support for it, please do not hesitate to submit a PR. |
Is there any update on this? It looks like I'm running into the same problem. To me it seems the addition of aliases should fix this problem. |
I can share my final solution or make a PR a bit later (updated version of the code I mentioned in the original post) |
Hi!
Recently I discovered an issue when using multiple column search with different relation using the same table. Here's what I mean.
I have a model with relations:
and two columns in the datatable with these relation (country_from.name, country_to.name). I need to use filtering by both columns at the same time and I got a problem: when the second relation is applied the join is omitted since it's already joined and same table used in WHERE condition:
This happens because of this code:
laravel-datatables/src/EloquentDataTable.php
Lines 251 to 253 in 9e96d1f
It makes since until you need to join the same table. I figured out a way to make it work like it supposed to in my case, but Im not sure it's PR worth hack and it's not thoroughly tested :) Here's what I did.
Generate an alias for the table if it's already joined and return it with performJoin method (sorry, not the cleanest code):
and use this alias in the end of
joinEagerLoadedColumn()
method:after that the lib can generate accurate query:
Maybe I'm missing something and there's a native or more simple way to do that without code changes? Please let me know, thanks
The text was updated successfully, but these errors were encountered: