Are Globals supposed to allow me to create multiple records?

default discord avatar
unclaimed1052last year
2

Hello, today I'm using globals for the first time. As I understand it, and as the payload AI chatbot confirmed, globals are supposed to allow me to create a single record. For some reason, inside my admin panel I can create multiple. Here is my code


import { GlobalConfig } from 'payload/types'
import { TextLeft } from '../CustomComponents/ShopBlockImage1'
import Products from './Products'
import ShopMedia from './ShopMedia'

const Shop: GlobalConfig = {
  slug: 'shop',
  access: {
    read: () => true,
    // create: () => true,
    update: () => true,
    // delete: () => true,
  },
  fields: [
    {
      name: 'title',
      type: 'text',
      label: 'Titolo'
    },
    {
      name: 'description',
      type: 'textarea',
      label: 'Descrizione'
    },
    {
      type: 'upload',
      relationTo: ShopMedia.slug,
      name: 'shopHeaderImage',
      label: 'Foto header'
    },
    {
      type: 'ui',
      name: 'shopBlock1',
      admin: {
        components: {
          Field: TextLeft,
        },
      },
    },
    {
      name: 'shopProducts',
      type: 'relationship',
      relationTo: Products.slug,
      hasMany: true,
    },
    // Add a relationship to products, so when an admin wants to list and de-list products from the shop it is easier as it doesn't need to be deleted to remove it from the Shop page
  ],
}

export default Shop


Is it normal? Thanks!



Payload "version": "1.11.5"



Screenshot of my admin panel



I have tried to drop the Shop collection from MongoDB and populated it again, but it showed the same behavior (can create multiple records)

  • default discord avatar
    imcorfitzlast year

    Where in your

    payload.config.ts

    have you added this

    shop

    global?



    If it is in the

    collections

    array, that's the issue.. Needs to be inside a

    globals

    array in the config



    Screenshot_2023-07-29_at_11.33.14.png
  • default discord avatar
    unclaimed1052last year

    Oh... yes it was inside the collections array



    Thank you!

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.