diff --git a/packages/@sanity/form-builder/src/sanity/inputs/client-adapters/reference.js b/packages/@sanity/form-builder/src/sanity/inputs/client-adapters/reference.js index 2a5abe93827..c7af46f0c08 100644 --- a/packages/@sanity/form-builder/src/sanity/inputs/client-adapters/reference.js +++ b/packages/@sanity/form-builder/src/sanity/inputs/client-adapters/reference.js @@ -34,7 +34,7 @@ export function search(textTerm, referenceType) { const terms = textTerm.split(/\s+/) const typeConstraints = referenceType.to.map(type => buildConstraintFromType(type, terms)) - const query = `*[!(_id in path('drafts.**')) && ${typeConstraints.map(wrapInParens).join('||')}]` + const query = `*[!(_id in path('drafts.**')) && (${typeConstraints.map(wrapInParens).join('||')})]` return client.observable.fetch(query, {term: `${textTerm}*`}) } diff --git a/packages/test-studio/schemas/references.js b/packages/test-studio/schemas/references.js index f03753e9803..5d89541ae5b 100644 --- a/packages/test-studio/schemas/references.js +++ b/packages/test-studio/schemas/references.js @@ -20,6 +20,12 @@ export default { weak: true, to: {type: 'author'} }, + { + title: 'Reference to book or author', + name: 'multiTypeRef', + type: 'reference', + to: [{type: 'book'}, {type: 'author'}] + }, { name: 'array', type: 'array',