Reference options must be an object
Sanity Studio reports that a reference type expects `options` to be an object when the `options` key on a reference is set to anything other than a plain object.
The reference field lets you define options for the input component. Define these options under the options key, and set its value to an object.
Sanity Studio reports The reference type expects `options` to be an object when a reference type has an options key whose value is not a plain object. The error fires whenever options is set to anything other than a plain object, and only then. An array, a string, a number, and a boolean all trigger it.
Fix the options value
import {defineField, defineType} from 'sanity'
export default defineType({
name: 'blogPost',
type: 'document',
fields: [
defineField({
name: 'author',
type: 'reference',
to: [{type: 'person'}],
// Fails validation: `options` is an array, not an object
options: [{filter: 'age > 30'}],
}),
],
})import {defineField, defineType} from 'sanity'
export default defineType({
name: 'blogPost',
type: 'document',
fields: [
defineField({
name: 'author',
type: 'reference',
to: [{type: 'person'}],
options: {filter: 'age > 30'},
}),
],
})A reference accepts filter, filterParams, disableNew, and creationTypeFilter as options. Note that weak is a top-level property on the reference definition, not an option. See Reference type for the full list.
Related reference schema errors
- Reference field options must be nested under the options key: for when
filterorfilterParamssits on the root of the type instead of insideoptions. - Incompatible combination of params and filter: for when
filterParamsis combined with afilterfunction.