orchidsoftware / orchidsoftware/platform
Sort and Filter by a Specific Field of Relation Table
@tabuna is already working on this.
Since May 10, 2022.
- Dominant language
- PHP
- Stars
- 4.8k
- Forks
- 662
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 7
Description
Is your feature request related to a problem? Please describe.
I'm always frustrated when I make a layout with relation table and field, e.g., ...
- Let's say every
posthas oneauthor, and in here,authoris actually anidof anuser, so I will useuser_idinstead ofauthorin this post. - When we make a table of
posts, if we wants tosort()orfilter(), we can easily make it with theuser_id. - But actually sort or filter the
user_idis not meaningful, because users expect it withuser_id.nameoruser_id.email.
I've already seen there are some discussions about this issue as well (e.g., https://github.com/orchidsoftware/platform/discussions/1766), but it seems using Eloquent Filter (https://orchid.software/en/docs/filters/#eloquent-filter) is the only way to solve it, however it is a little bit complicated.
Describe the solution you'd like
So, what I want to suggest is...
- What if the
modelis already defined its relationship withbelongsTo()orhasOne(), meaning a clear situation which shows 1:1 relation... - Orchid provides a simpler coding way to make its sort and filter, e.g., ...
public function columns(): array { return [
TD::make( 'user_id.name' , 'Author Name' )->sort()->filter( Input ::make() )
TD::make( 'user_id.email', 'Author Email' )->sort()->filter( Input ::make() )
# I hope just calling by dot notation makes sorting and filtering to be possible.
]; }
Describe alternatives you've considered
Because the Eloquent Filter gives the alternative solution, so my request is only about coding convenience.
I always really appreciate Orchid's cool structure which makes productions quick, and this suggestion may be loved by others as well. : )
Additional context
What if there is another easy way for this, and if I couldn't know it, I want to apologize first, and also please let me know that. T T
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.