Skip to content

Commit bf48af4

Browse files
authored
feat: add virtual property to the fields config (#7621)
## Description Adds `virtual` property to the fields config. Providing `true` completely disables the field in the DB, which is useful for [Virtual Fields](https://payloadcms.com/blog/learn-how-virtual-fields-can-help-solve-common-cms-challenges) Disables abillity to query by a field with `virtual: true`. Currently, they bloat the DB with unused tables / columns, which may as well introduce additional joins. Discussion #6270 Prev PR (this one contains only this feature): #6983 - [x] I have read and understand the [CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md) document in this repository. ## Type of change <!-- Please delete options that are not relevant. --> - [x] New feature (non-breaking change which adds functionality) - [x] This change requires a documentation update ## Checklist: - [x] I have added tests that prove my fix is effective or that my feature works - [x] Existing test suite passes locally with my changes - [x] I have made corresponding changes to the documentation
1 parent a7e8828 commit bf48af4

File tree

31 files changed

+254
-122
lines changed

31 files changed

+254
-122
lines changed

docs/fields/array.mdx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,25 @@ export const MyArrayField: Field = {
4242
| Option | Description |
4343
| ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
4444
| **`name`** \* | To be used as the property name when stored and retrieved from the database. [More](/docs/fields/overview#field-names) |
45-
| **`label`** | Text used as the heading in the [Admin Panel](../admin/overview) or an object with keys for each language. Auto-generated from name if not defined. |
45+
| **`label`** | Text used as the heading in the [Admin Panel](../admin/overview) or an object with keys for each language. Auto-generated from name if not defined. |
4646
| **`fields`** \* | Array of field types to correspond to each row of the Array. |
47-
| **`validate`** | Provide a custom validation function that will be executed on both the [Admin Panel](../admin/overview) and the backend. [More](/docs/fields/overview#validation) |
47+
| **`validate`** | Provide a custom validation function that will be executed on both the [Admin Panel](../admin/overview) and the backend. [More](/docs/fields/overview#validation) |
4848
| **`minRows`** | A number for the fewest allowed items during validation when a value is present. |
4949
| **`maxRows`** | A number for the most allowed items during validation when a value is present. |
50-
| **`saveToJWT`** | If this field is top-level and nested in a config supporting [Authentication](/docs/authentication/overview), include its data in the user JWT. |
51-
| **`hooks`** | Provide Field Hooks to control logic for this field. [More details](../hooks/fields). |
52-
| **`access`** | Provide Field Access Control to denote what users can see and do with this field's data. [More details](../access-control/fields). |
50+
| **`saveToJWT`** | If this field is top-level and nested in a config supporting [Authentication](/docs/authentication/overview), include its data in the user JWT. |
51+
| **`hooks`** | Provide Field Hooks to control logic for this field. [More details](../hooks/fields). |
52+
| **`access`** | Provide Field Access Control to denote what users can see and do with this field's data. [More details](../access-control/fields). |
5353
| **`hidden`** | Restrict this field's visibility from all APIs entirely. Will still be saved to the database, but will not appear in any API or the Admin Panel. |
5454
| **`defaultValue`** | Provide an array of row data to be used for this field's default value. [More](/docs/fields/overview#default-values) |
5555
| **`localized`** | Enable localization for this field. Requires [localization to be enabled](/docs/configuration/localization) in the Base config. If enabled, a separate, localized set of all data within this Array will be kept, so there is no need to specify each nested field as `localized`. |
5656
| **`required`** | Require this field to have a value. |
5757
| **`labels`** | Customize the row labels appearing in the Admin dashboard. |
58-
| **`admin`** | Admin-specific configuration. [More details](#admin-options). |
58+
| **`admin`** | Admin-specific configuration. [More details](#admin-options). |
5959
| **`custom`** | Extension point for adding custom data (e.g. for plugins) |
6060
| **`interfaceName`** | Create a top level, reusable [Typescript interface](/docs/typescript/generating-types#custom-field-interfaces) & [GraphQL type](/docs/graphql/graphql-schema#custom-field-schemas). |
6161
| **`dbName`** | Custom table name for the field when using SQL Database Adapter ([Postgres](/docs/database/postgres)). Auto-generated from name if not defined. |
6262
| **`typescriptSchema`** | Override field type generation with providing a JSON schema |
63+
| **`virtual`** | Provide `true` to disable field in the database. See [Virtual Fields](https://payloadcms.com/blog/learn-how-virtual-fields-can-help-solve-common-cms-challenges) |
6364

6465
_\* An asterisk denotes that a property is required._
6566

docs/fields/blocks.mdx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,18 @@ export const MyBlocksField: Field = {
4747
| **`validate`** | Provide a custom validation function that will be executed on both the Admin Panel and the backend. [More](/docs/fields/overview#validation) |
4848
| **`minRows`** | A number for the fewest allowed items during validation when a value is present. |
4949
| **`maxRows`** | A number for the most allowed items during validation when a value is present. |
50-
| **`saveToJWT`** | If this field is top-level and nested in a config supporting [Authentication](/docs/authentication/overview), include its data in the user JWT. |
51-
| **`hooks`** | Provide Field Hooks to control logic for this field. [More details](../hooks/fields). |
52-
| **`access`** | Provide Field Access Control to denote what users can see and do with this field's data. [More details](../access-control/fields). |
50+
| **`saveToJWT`** | If this field is top-level and nested in a config supporting [Authentication](/docs/authentication/overview), include its data in the user JWT. |
51+
| **`hooks`** | Provide Field Hooks to control logic for this field. [More details](../hooks/fields). |
52+
| **`access`** | Provide Field Access Control to denote what users can see and do with this field's data. [More details](../access-control/fields). |
5353
| **`hidden`** | Restrict this field's visibility from all APIs entirely. Will still be saved to the database, but will not appear in any API response or the Admin Panel. |
5454
| **`defaultValue`** | Provide an array of block data to be used for this field's default value. [More](/docs/fields/overview#default-values) |
5555
| **`localized`** | Enable localization for this field. Requires [localization to be enabled](/docs/configuration/localization) in the Base config. If enabled, a separate, localized set of all data within this field will be kept, so there is no need to specify each nested field as `localized`. |
5656
| **`unique`** | Enforce that each entry in the Collection has a unique value for this field. |
5757
| **`labels`** | Customize the block row labels appearing in the Admin dashboard. |
58-
| **`admin`** | Admin-specific configuration. [More details](#admin-options). |
58+
| **`admin`** | Admin-specific configuration. [More details](#admin-options). |
5959
| **`custom`** | Extension point for adding custom data (e.g. for plugins) |
6060
| **`typescriptSchema`** | Override field type generation with providing a JSON schema |
61+
| **`virtual`** | Provide `true` to disable field in the database. See [Virtual Fields](https://payloadcms.com/blog/learn-how-virtual-fields-can-help-solve-common-cms-challenges) |
6162

6263
_\* An asterisk denotes that a property is required._
6364

docs/fields/checkbox.mdx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,17 @@ export const MyCheckboxField: Field = {
3434
| **`label`** | Text used as a field label in the Admin Panel or an object with keys for each language. |
3535
| **`validate`** | Provide a custom validation function that will be executed on both the Admin Panel and the backend. [More](/docs/fields/overview#validation) |
3636
| **`index`** | Build an [index](/docs/database/overview) for this field to produce faster queries. Set this field to `true` if your users will perform queries on this field's data often. |
37-
| **`saveToJWT`** | If this field is top-level and nested in a config supporting [Authentication](/docs/authentication/overview), include its data in the user JWT. |
38-
| **`hooks`** | Provide Field Hooks to control logic for this field. [More details](../hooks/fields). |
39-
| **`access`** | Provide Field Access Control to denote what users can see and do with this field's data. [More details](../access-control/fields). |
37+
| **`saveToJWT`** | If this field is top-level and nested in a config supporting [Authentication](/docs/authentication/overview), include its data in the user JWT. |
38+
| **`hooks`** | Provide Field Hooks to control logic for this field. [More details](../hooks/fields). |
39+
| **`access`** | Provide Field Access Control to denote what users can see and do with this field's data. [More details](../access-control/fields). |
4040
| **`hidden`** | Restrict this field's visibility from all APIs entirely. Will still be saved to the database, but will not appear in any API or the Admin Panel. |
4141
| **`defaultValue`** | Provide data to be used for this field's default value, will default to false if field is also `required`. [More](/docs/fields/overview#default-values) |
4242
| **`localized`** | Enable localization for this field. Requires [localization to be enabled](/docs/configuration/localization) in the Base config. |
4343
| **`required`** | Require this field to have a value. |
44-
| **`admin`** | Admin-specific configuration. [More details](../admin/fields#admin-options). |
44+
| **`admin`** | Admin-specific configuration. [More details](../admin/fields#admin-options). |
4545
| **`custom`** | Extension point for adding custom data (e.g. for plugins) |
4646
| **`typescriptSchema`** | Override field type generation with providing a JSON schema |
47+
| **`virtual`** | Provide `true` to disable field in the database. See [Virtual Fields](https://payloadcms.com/blog/learn-how-virtual-fields-can-help-solve-common-cms-challenges) |
4748

4849
_\* An asterisk denotes that a property is required._
4950

0 commit comments

Comments
 (0)