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 support for polymorphic uploads (#14363)
This PR adds support for polymorphic uploads similar to polymorphic
relationships. Closes
#13912
It works with bulk upload as well and in the bulk uploader you can
choose which collection the files are uploaded into.
You can enable this by adding an array of slugs into `relationTo`:
```ts
import type { CollectionConfig } from 'payload'
export const ExampleCollection: CollectionConfig = {
slug: 'example-collection',
fields: [
{
name: 'media',
type: 'upload',
relationTo: ['images', 'documents', 'videos'], // references multiple upload collections
},
],
}
```
It can also be combined with `hasMany`:
```ts
import type { CollectionConfig } from 'payload'
export const ExampleCollection: CollectionConfig = {
slug: 'example-collection',
fields: [
{
name: 'media',
type: 'upload',
relationTo: ['images', 'documents', 'videos'], // references multiple upload collections
hasMany: true, // allows multiple uploads
},
],
}
```
**Known issue**: #12014
Filtering by polymorphic relationships is currently broken and I'll work
on that in a separate PR.
|**`name`**\*| To be used as the property name when stored and retrieved from the database. [More details](/docs/fields/overview#field-names). |
50
-
|**`relationTo`**\*| Provide a single collection `slug` to allow this field to accept a relation to. **Note: the related collection must be configured to support Uploads.**|
50
+
|**`relationTo`**\*| Provide a single collection `slug`or an array of slugs to allow this field to accept a relation to. **Note: the related collections must be configured to support Uploads.**|
51
51
|**`filterOptions`**| A query to filter which options appear in the UI and validate against. [More details](#filtering-upload-options). |
52
52
|**`hasMany`**| Boolean which, if set to true, allows this field to have many relations instead of only one. |
53
53
|**`minRows`**| A number for the fewest allowed items during validation when a value is present. Used with hasMany. |
@@ -140,3 +140,40 @@ The `upload` field on its own is used to reference documents in an upload collec
140
140
relationship. If you wish to allow an editor to visit the upload document and see where it is being used, you may use
141
141
the `join` field in the upload enabled collection. Read more about bi-directional relationships using
142
142
the [Join field](./join)
143
+
144
+
## Polymorphic Uploads
145
+
146
+
Upload fields can reference multiple upload collections by providing an array of collection slugs to the `relationTo` property.
0 commit comments