Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: queriable / sortable / useAsTitle virtual fields linked with a relationship field #11805

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

r1tsuu
Copy link
Member

@r1tsuu r1tsuu commented Mar 20, 2025

This PR adds an ability to specify a virtual field in this way

{
  slug: 'posts',
  fields: [
    {
      name: 'title',
      type: 'text',
      required: true,
    },
  ],
},
{
  slug: 'virtual-relations',
  fields: [
    {
      name: 'postTitle',
      type: 'text',
      virtual: {
        path: 'title', // foreign path
        relationship: 'post', // path to the relationship field
      },
    },
    {
      name: 'post',
      type: 'relationship',
      relationTo: 'posts',
    },
  ],
},

Then, every time you query virtual-relations, postTitle will be automatically populated (even if using depth: 0) on the db level. This field also, unlike virtual: true is available for querying / sorting / useAsTitle.

@r1tsuu r1tsuu marked this pull request as draft March 20, 2025 21:56
@r1tsuu r1tsuu marked this pull request as ready for review March 21, 2025 15:00
@r1tsuu r1tsuu requested a review from DanRibbens March 21, 2025 15:00
@r1tsuu r1tsuu force-pushed the feat/virtual-field-better branch from 0c76dab to e83a729 Compare March 24, 2025 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant