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.

field admin condition based on separate collection/ promise

default discord avatar
wrobson-lllowlast year
1 1

I have a field in a collection called "accounts" that has a field "attachments" that I would like to show conditionally based on what is present in another collection "licenses." Is there a way to do this? I attempted to do this using payload.find(), however "condition" only accepts a function that returns a boolean not a Promise.

  • Selected Answer
    discord user avatar
    jmikrut
    last year

    Hey there! Good question. Conditional logic runs very very frequently, and it should be optimized as heavy as possible. So they explicitly do not allow asynchronous actions, and you definitely would not want to be fetching anything directly within a condition because of this. Could you populate the data from your licenses collection on your document that would be requiring the condition? You would need to replicate the shape of the license data on your accounts collection (commonly referred to as a virtual field) where the data wouldn’t actually be stored, but could be accessed in your conditional logic as usual. Does that make sense?

    1 reply
  • default discord avatar
    wrobson-lllowlast year

    Yes! It totally does. Thanks for the quick response!

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..