How to reference Upload from another collection #827
Answered
by
denolfe
momin-riyadh
asked this question in
Q&A
-
How can I add Media(image, video, etc) in Post Collection const Posts = {
slug: 'posts',
admin: {
defaultColumns: ['title', 'author', 'category', 'tags', 'status'],
useAsTitle: 'title',
},
access: {
read: () => true,
},
fields: [
{
name: 'title',
type: 'text',
},
{
name: 'author',
type: 'relationship',
relationTo: 'users',
},
{
name: 'publishedDate',
type: 'date',
},
{
name: 'category',
type: 'relationship',
relationTo: 'categories'
},
{
name: 'tags',
type: 'relationship',
relationTo: 'tags',
hasMany: true,
},
{
name: 'content',
type: 'richText'
},
{
name: 'status',
type: 'select',
options: [
{
value: 'draft',
label: 'Draft',
},
{
value: 'published',
label: 'Published',
},
],
defaultValue: 'draft',
admin: {
position: 'sidebar',
}
}
],
}
export default Posts; |
Beta Was this translation helpful? Give feedback.
Answered by
denolfe
Jul 26, 2022
Replies: 1 comment
-
You can do this by adding a relationship field with {
name: 'image',
type: 'upload',
required: true,
relationTo: 'media',
}, More info in the docs on the relationship and upload pages. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
denolfe
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can do this by adding a relationship field with
relationTo
to your media collection's slug like this:More info in the docs on the relationship and upload pages.