Jun 25, 2021
0
Level 1
How to make a field in a parent/children relationship sortable on display page?
In a typical blog system with a user/posts relationship, if the post model (user_id, title, text) is added to the Nova resources, how to make the fields from user model (e.g. user.name) sortable on the display page?
The user.name along with other fields from posts table can be easily displayed on the post resource using the following entries:
ID::make(__('ID'), 'id')->sortable(),
Text::make('User', 'user.name')->sortable(),
Text::make('Title')->sortable(),
Text::make('Text')->sortable(),
But the sort function throws a SQL exception:
Column not found. 1054 Unknown column 'user.name' in 'order clause' (SQL: select * from 'posts' order by 'user.name' asc ...)
Thanks!
Please or to participate in this conversation.