Troubleshooting missing category name in Sanity Studio
17 replies
Last updated: Sep 8, 2022
O
Hey. Can someone explain why I am not getting category name from reference.
tag:
Have I forgot to add something?
tag:
export default { name : "customTag", title: "Tag", type : "object", fields : [ { title: "Tag", name: "tag", type : "string", }, { title: 'Director', name: 'director', type: 'reference', to: [{type: 'category'}] } ] }
Have I forgot to add something?
Sep 7, 2022, 10:11 AM
D
If you need a
namefrom a groq query, you would need to expand the reference.
director-> { name }
Sep 7, 2022, 10:14 AM
O
Can you specify where I should do that? I haven't seen this syntax before. Not sure where in code it belongs
I tried like so but it did not work so I assume it's not where it belongs
I tried like so but it did not work so I assume it's not where it belongs
{ title: 'Director', name: 'director-> { name }', type: 'reference', to: [{type: 'category'}] }
Sep 7, 2022, 10:24 AM
O
Cause I need to see the name in sanity studio not in front end.
Sep 7, 2022, 10:38 AM
D
You need it in the list where you reference it in Sanity?
Then in you category schema, you will need to change the preview i would think.
https://www.sanity.io/docs/previews-list-views
Then in you category schema, you will need to change the preview i would think.
https://www.sanity.io/docs/previews-list-views
Sep 7, 2022, 10:47 AM
K
What are you trying to do and what are you currently facing as a problem please? 🙂
Sep 7, 2022, 12:03 PM
O
we have predefined categories. On my colleges pc we can see the category that we chose while on mine we don't see it.
Sep 7, 2022, 12:07 PM
K
What does the schema look like for that field?
Sep 7, 2022, 12:09 PM
O
export default { name:'filterTags', title: 'Filter Tags', type: 'document', fields: [ { name: "categoryTag", title: "Category Tag", type: "reference", to: [{type: 'category'}] }, { name: "tagName", title: "Tag Name", description: "", type: "string", } ] }
Sep 7, 2022, 12:20 PM
O
I assume that it's the server connection problem. No one else has this problem in the team and they see the description in sanity studio. But I could be very wrong as well 😅
Sep 7, 2022, 12:22 PM
K
And the schema for
category?
Sep 7, 2022, 12:23 PM
O
export default { name: 'category', title: 'Category Folder', type: 'document', fields: [ { name: "categoryTitle", title: "Category Title", type: "string", description: '', }, ] }
Sep 7, 2022, 12:25 PM
K
Ah yes, that makes sense. By default, the preview relies on a
titleproperty I think. Because your field is named differently, you’ll have to adjust the preview from your
categorydocument.
export default { … preview: { select: { title: 'categoryTitle' }, prepare({ title }) { return { title } } }
Sep 7, 2022, 12:27 PM
O
I did this but it didn't help. Also every one else works on the same repo and they see the category name inside the box without this extra block of code
export default { name: 'category', title: 'Category Folder', type: 'document', fields: [ { name: "categoryTitle", title: "Category Title", type: "string", description: '', }, ], preview: { select: { title: 'categoryTitle' }, prepare({ title }) { return { title } }, } }
Sep 7, 2022, 12:33 PM
S
I have the exact same code as Odeta and it works fine for me.edit: Im on Macbook
Sep 7, 2022, 12:34 PM
D
Empty cache in browser maybe?
Sep 7, 2022, 12:34 PM
O
did not help
Sep 7, 2022, 12:39 PM
S
Hello
user E
you don’t need to select and prepare and then return if you use this simple structure:export default { name: 'category', title: 'Category Folder', type: 'document', fields: [ { name: "title", title: "Category Title", type: "string", }, ], preview: { title: 'title' } }
Sep 8, 2022, 4:35 PM
Sanity– build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.