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
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 },
},
2) 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' },
},
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');
}
}
}
}
});
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.
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. :)
The view section should now be done as a custom view. This use-case becomes rather simple if we land: https://github.com/keystonejs/keystone/pull/2885
Most helpful comment
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.