Is it Possible to Pass a Document Reference to Validation and Access the Dereferenced Fields?
Last updated: Aug 6, 2021
Heyyy I have a schema validation question. Is it possible to pass a doc reference to validation and access the dereferenced fields? It seems not. It also seems like the solution is to perform a fetch to get it. Is there anything I'm missing here?
Aug 6, 2021, 6:57 PM
I expect you’re right that a fetch will be involved. I would use the Sanity client and get the data you’re after in that fetch (in my case below, the title). This snippet lets you paste a document _id into a string field and if it exists, it throws a validation error that contains that document’s title. I’d recommend looking at this function to add some robustness to the query: