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

Limit (filter) Relationship to a sub-set of List items #472

Closed
mikehazell opened this issue Oct 25, 2018 · 4 comments
Closed

Limit (filter) Relationship to a sub-set of List items #472

mikehazell opened this issue Oct 25, 2018 · 4 comments

Comments

@mikehazell
Copy link
Contributor

In K4 it was possible to define a filter on a Relationship field type. This allowed restricting relationships created through the admin ui to a subset of a List.

Related to: #376, #352

Example use cases

  1. A Post has a relationship field for the assigned reviewer. Only User's with isAdmin === true can be assigned.

In K4 this was defined on the List as follows:

reviewer: {
    type: Relationship,
    ref: 'User',
    filters: { isAdmin: true },
},
  1. A Site can have featuredTags. Those Tags must be related to the current site. ie:
featuredTags: {
    type: Relationship,
    ref: 'Tag',
    many: true,
    filters: { site: ':_id' },
},
@jesstelford
Copy link
Contributor

jesstelford commented Oct 25, 2018

This could be possible when we expose the hooks:

keystone.createList('Post', {
  fields: {
    reviewer: {
      type: Relationship,
      ref: 'User',
      hooks: {
        preUpdate: (data, item, context) => {
          if (!data.isAdmin) throw new Error('Not allowed');
        }
      }
    }
  }
});

@mikehazell
Copy link
Contributor Author

Yes that's one side of it. The other side is that in the Admin UI you are not presented with invalid options when creating the relationship.

@nathsimpson nathsimpson pinned this issue Jan 3, 2019
@timleslie timleslie unpinned this issue Jan 8, 2019
@stale
Copy link

stale bot commented Nov 16, 2019

It looks like you haven't had a response in over 3 months. Sorry about that! We've flagged this issue for special attention. It wil be manually reviewed by maintainers, not automatically closed. If you have any additional information please leave us a comment. It really helps! Thank you for you contributions. :)

@stale stale bot added the needs-review label Nov 16, 2019
@MadeByMike
Copy link
Contributor

The view section should now be done as a custom view. This use-case becomes rather simple if we land: #2885

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants