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
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
|**`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. |
46
46
|**`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)|
48
48
|**`minRows`**| A number for the fewest allowed items during validation when a value is present. |
49
49
|**`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). |
53
53
|**`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. |
54
54
|**`defaultValue`**| Provide an array of row data to be used for this field's default value. [More](/docs/fields/overview#default-values)|
55
55
|**`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`. |
56
56
|**`required`**| Require this field to have a value. |
57
57
|**`labels`**| Customize the row labels appearing in the Admin dashboard. |
|**`custom`**| Extension point for adding custom data (e.g. for plugins) |
60
60
|**`interfaceName`**| Create a top level, reusable [Typescript interface](/docs/typescript/generating-types#custom-field-interfaces) & [GraphQL type](/docs/graphql/graphql-schema#custom-field-schemas). |
61
61
|**`dbName`**| Custom table name for the field when using SQL Database Adapter ([Postgres](/docs/database/postgres)). Auto-generated from name if not defined. |
62
62
|**`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)|
63
64
64
65
_\* An asterisk denotes that a property is required._
Copy file name to clipboardExpand all lines: docs/fields/blocks.mdx
+5-4Lines changed: 5 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,17 +47,18 @@ export const MyBlocksField: Field = {
47
47
|**`validate`**| Provide a custom validation function that will be executed on both the Admin Panel and the backend. [More](/docs/fields/overview#validation)|
48
48
|**`minRows`**| A number for the fewest allowed items during validation when a value is present. |
49
49
|**`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). |
53
53
|**`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. |
54
54
|**`defaultValue`**| Provide an array of block data to be used for this field's default value. [More](/docs/fields/overview#default-values)|
55
55
|**`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`. |
56
56
|**`unique`**| Enforce that each entry in the Collection has a unique value for this field. |
57
57
|**`labels`**| Customize the block row labels appearing in the Admin dashboard. |
|**`custom`**| Extension point for adding custom data (e.g. for plugins) |
60
60
|**`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)|
61
62
62
63
_\* An asterisk denotes that a property is required._
Copy file name to clipboardExpand all lines: docs/fields/checkbox.mdx
+5-4Lines changed: 5 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,16 +34,17 @@ export const MyCheckboxField: Field = {
34
34
|**`label`**| Text used as a field label in the Admin Panel or an object with keys for each language. |
35
35
|**`validate`**| Provide a custom validation function that will be executed on both the Admin Panel and the backend. [More](/docs/fields/overview#validation)|
36
36
|**`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). |
40
40
|**`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. |
41
41
|**`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)|
42
42
|**`localized`**| Enable localization for this field. Requires [localization to be enabled](/docs/configuration/localization) in the Base config. |
43
43
|**`required`**| Require this field to have a value. |
|**`custom`**| Extension point for adding custom data (e.g. for plugins) |
46
46
|**`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)|
47
48
48
49
_\* An asterisk denotes that a property is required._
0 commit comments