orchidsoftware / orchidsoftware/platform

Sort and Filter by a Specific Field of Relation Table

Open
#2,234 5 comments 4 reactions 1 assignee View on GitHub

@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 post has one author, and in here, author is actually an id of an user, so I will use user_id instead of author in this post.
  • When we make a table of posts, if we wants to sort() or filter(), we can easily make it with the user_id.
  • But actually sort or filter the user_id is not meaningful, because users expect it with user_id.name or user_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 model is already defined its relationship with belongsTo() or hasOne(), 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.