field admin condition based on separate collection/ promise

default discord avatar
wrobson-lllow8 months ago
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
    8 months ago

    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-lllow8 months ago

    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 help straight from the Payload team with an Enterprise License.