Hey guys
I have a "movies" collection, and I field called "related movies'. When returning the movie, I want to populate the "related movies' field. So, I used afterreadhook where I make a call to "movies" collection to get 5 random movies. Seems like afterread hook got triggered for other movies as well and I ended up in the infinite loop. Is there a way to stop it after the first time?
Morning! Can we see your logic please?
It seems like passing
contextto the afterChange hook will help here. You can check the documentation, the first link
Context - When to use ContextYeah, thank you guys. Made it work. If someone needs reference -
https://payloadcms.com/docs/hooks/context#preventing-infinite-loopsStar
Discord
online
Get dedicated engineering support directly from the Payload team.