Alert user if they are deleting an item that is referenced somewhere else

default discord avatar
mrl7last year
1

Hi all, is there a way in payload to alert a user if they are deleting an item that is referenced somewhere else?



e.g. If I have a collection of

newsPosts

and these are used as a reference on the

homePage

. A user can select what

newsPosts

they wish to show on the

homePage

.



If a user removes a

newsPost

, it breaks the

homePage

as the reference no longer exists. I would like to alert or stop the user from deleting that news post until they have removed the reference. Is this possible?

  • default discord avatar
    majohannsenlast year

    You could use a beforeDelete hook on the newsPost collection and check if the homePage references this Post. If so you could then throw an error to prevent the post from being deleted.



    But i don't know if this is the best solution bc when there are many collections that can reference this collection (e.g. Media) all these collections have to be checked one by one.

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.