OrderBy relationated field #1537
Answered
by
thetutlage
rodolphonetto
asked this question in
Help
-
Hi guys, I can't use a relationated field to orderBy a query, let me show you an exampe I have that
It gives me that error Unknown column 'solicitation_types.title' in 'order clause' How can I order by a field in the relation? |
Beta Was this translation helpful? Give feedback.
Answered by
thetutlage
Aug 31, 2020
Replies: 1 comment 2 replies
-
Yes coz relationships are loaded in a separate query after the main query. What you need is a order by subquery. Following should do it. .orderByRaw(
Database.raw('select title from solicitation_types where solicitation_types.FK = main_table.PK'),
'desc'
) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
rodolphonetto
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes coz relationships are loaded in a separate query after the main query. What you need is a order by subquery. Following should do it.