Sortable by morph-relation
Hi folks,
I'm trying to make a column sortable, which is beeing referenced by a morph-relation.
I tried using
->sortable(query: fn($query, $direction) => $query->orderBy('relationame.relationproperty', $direction))
and made sure that all possible morphs got said relationproperty, but to no avail. Laravel tells me Unknown column 'relationname.relationproperty' in 'order clause'
and the SQL only seems to use the basemodel and not the relationmodel. Am I missing something here?2 Replies
try asking in the Laravel server since this is more of an Eloquent question isnt it
Ah okay - I see. To anyone else reading this: It's possible via a left join inside the original query.
For me - since my dataset can become pretty large, I will not make it sortable via morph, but will implement the column inside the model that I am morphing.