Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Is is possible to have an optional unique field?

default discord avatar
thgh.2 years ago
5

It seems that unique implies required.

  • default discord avatar
    hades2000822 years ago

    Not true. I’ve had many occasions in other systems where I needed SQL indexes for “unique or null”

  • default discord avatar
    thgh.2 years ago

    Agree, how to do it in payload?

  • default discord avatar
    hades2000822 years ago

    Could you do it in a custom validate function?

  • default discord avatar
    thgh.2 years ago

    Probably, but I think that would introduce a potential race condition. Created a discussion over here:

    https://github.com/payloadcms/payload/discussions/2072
  • default discord avatar
    jessrynkar2 years ago

    Going to mark an answered as the discussion has moved to github here.

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.