You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If your admin-only functions rely on specific fields, e.g. admin.formatAdminURL, there's a new admin.forceSelect property that is specifically designed to ensure these fields exist when queried within the admin panel. This is useful to avoid forcing these fields to be selected on all external-facing APIs, which is what forceSelect (top-level) would do.
To solve this cleanly and natively, I propose extending the current forceSelect API.
Instead of only supporting : true, it could also allow specifying a function:
I think supporting a function here is a good call, although I see the implementation a bit differently that you've described. We could drop forceSelect entirely (including my proposed admin.forceSelect), and replace it with a single select function that allows you to dynamically modify it at the request level.
Another approach I implemented while developing my Pages plugin, which relies heavily on virtual fields, is to add a custom beforeOperation hook to the collection.
I actually like this idea a lot. We could drop support for forceSelect entirely, since you can modify select in a beforeOperation hook just the same. It's less discoverable in the config but significantly less code under the hood, plus it really feels like mutating operational level args should be done in the beforeOperation hook, by definition.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enables the Select API in the list view by default. Deprecates the experimental
admin.listViewSelectAPIproperty, as this is now the default behavior.import type { CollectionConfig } from 'payload'; const MyCollection: CollectionConfig = { slug: 'pages', admin: { - listViewSelectAPI: true } }Optional
If your admin-only functions rely on specific fields, e.g.
admin.formatAdminURL, there's a newadmin.forceSelectproperty that is specifically designed to ensure these fields exist when queried within the admin panel. This is useful to avoid forcing these fields to be selected on all external-facing APIs, which is whatforceSelect(top-level) would do.import type { CollectionConfig } from 'payload'; const MyCollection: CollectionConfig = { slug: 'pages', admin: { + forceSelect: { + _status: true + } } }Codemod
To migrate automatically, there's a codemod for this change available by running:
The codemod is unaware of your admin-only function dependencies, however, so you may have to add the
admin.forceSelectdefinitions by hand, as needed.