field admin condition based on separate collection/ promise

default discord avatar
last month
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.

  • discord user avatar
    Payload Team
    last month

    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
    last month

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

Open the post
Continue the discussion in GitHub
Like what we're doing?
Star us on GitHub!


Connect with the Payload Community on Discord



Can't find what you're looking for?

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