Global Document Reference
Schema type reference documentation for Global Document References.
Global document references expand the concept of the reference type to support referencing documents in other datasets.
Global document references are limited to Media Library
Global document references are a new schema type. At this time, only Media Library's aspects feature supports use of global document references.
Like standard references, global document references can be either strong (default) or weak. A strong reference will ensure that the document it points to actually exists and will not allow the deletion of a document that any other document refers to. A weak reference allows pointing to documents that may not exist (yet) or have been deleted.
Properties
Requiredtypestring
Value must be set to
globalDocumentReference
.Requirednamestring
Required. The field name. This will be the key in the data record.
RequiredresourceTypestring
The resource type containing the connected documents. At the moment, Media Library can reference the
dataset
resource type.RequiredresourceIdstring
The ID of the target resource. A resourceId is made up of the projectId and the dataset name, connected by a
.
. For example:projectId.datasetName
.w3dbef.production
wm2efj.staging
Requiredtoarray
Must contain an array naming all the types which may be referenced. For example:
[{type: 'person'}]
. See more examples below.weakboolean
If set to
true
the reference will be made weak. This allows references to point at documents that may or may not exist, such as a document that has not yet been published or a document that has been deleted (or indeed an entirely imagined document).titlestring
Human-readable label for the field.
optionsobject
Further configure the schema type. See details in the "options" section below.
Options
filterstring
A GROQ filter string (the contents between the square brackets), such as
language == "en-US"
.filterParamsobject
Object of parameters for the GROQ-filter specified in
filter
.
Example
import { defineAssetAspect } from 'sanity'
export default defineAssetAspect({
name: 'photographer',
title: 'Photographer',
type: 'globalDocumentReference',
description: 'Select the photographer.',
resourceType: 'dataset',
resourceId: '3do82whm.example',
weak: true,
to: [
{
type: 'photographer',
preview: {
select: {
title: 'name'
}
}
}
]
})
Was this page helpful?