Like what we’re doing? Star us on GitHub!

Is is possible to have an optional unique field?

thgh
last month
5

It seems that unique implies required.

  • Kyr
    last month

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

  • thgh
    last month

    Agree, how to do it in payload?

  • Kyr
    last month

    Could you do it in a custom validate function?

  • thgh
    last month

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

    https://github.com/payloadcms/payload/discussions/2072
  • jesschow
    Payload Team
    4 weeks ago

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

Open the post
Continue the discussion in Discord
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More