laravel-datatables
laravel-datatables copied to clipboard
Fixes issue for ordering by a relationship.
This fixes an issue when ordering by a HasMany
relationship due to no selects being on the query and overriding the original models id with the id from the relationship.
The PR looks good and tests are passing. Will check this asap.
BTW, if possible, can you add a test for this scenario? Thanks! 🍻
@Nathanw I just realized after testing this that allowing sort on HasMany
relationship would yield to multiple duplicate records since we are not grouping on sql level.
Duplicate records when sorted via User -> HasMany-> Post
On the other hand, I think it does fix sorting on HasMany relationship.
Do you think we should merge this and allow the unnecessary duplicate results?
Any feedbacks from other users?
@yajra Almost every relation cause duplicate results. It's always correct to groupBy
the query inside your DataTable
class manually. I encountered this problem over 100 times.
Nowadays I always include $query->groupBy('my_table');
just before I return the results.
I feel like this should be merged and groupBy
thing should be mentioned as a "Good Practice" in the Docs.