Model 1 => hasManyThrought => Model 2, Model 3
so, Model 1 can have many Model 4. Which one you want to sort by?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi guys,
I'm doing a table sort and one of the columns that I need to sort has data that are located in a different table. Table that contains data to sort is through three relations away. The issue is that the sort takes too long, so the result is a timeout.
There are relationships: Model 1 => hasManyThrought => Model 2, Model 3 Model 3 => belongsTo => Model 4 (my field)
And I need to sort data in Model 1 by column in Model 4.
I have all relationships loaded with eager loading. I tried to sort it as the collection (sortBy, sortByDesc), and I tried to sort them by raw SQL. What do you think is the best option? What if there are more of those columns?
Thank you
Please or to participate in this conversation.