0

Im having issues with references in Sanity. Im setting some color themes in the root of my Sanity schema:

defineField({
      name: 'articletheme',
      title: 'Article theme',
      description: 'Create 4 themes for article blocks',
      type: 'array',
      validation: (Rule) => Rule.required(),
      of: [{ type: 'articleThemeBlock' }],
    }),

In one of the blocks I would like to reference the theme array to select which color theme that block should use.

Ive tried this, but it fails:

defineField({
      name: 'theme',
      title: 'Theme',
      type: 'reference',
      to: [
        {
          type: 'array',
          of: [
            {
              type: 'articletheme',
            },
          ],
        },
      ],
    }),

Any suggestions?

Tore
  • 99
  • 10

2 Answers2

0

Very confusing but the your second schema above looks incorrect, try this -

defineField({
  name: 'theme',
  title: 'Theme',
  type: 'array',  // changed from reference to array
  to: [
    {
      type: 'reference',  // changed from array to reference
      of: [
        {
          type: 'articletheme',
        },
      ],
    },
  ],
}),
Ejaz
  • 1,504
  • 3
  • 25
  • 51
0

Try it like this, type array, an array OF reference, referencing TO type articletheme `

defineField({
  name: 'theme',
  title: 'Theme',
  type: 'array',  // changed from reference to array
  of: [
    {
      type: 'reference',  // changed from array to reference
      to: [
        {
          type: 'articletheme',
        },
      ],
    },
  ],
}),

`

Bounews
  • 121
  • 1
  • 1
  • 5