-
Hello again! I am really loving payload cms so far 🙌 We encountered one problem though: Is there a way to specifically turn off hooks on a CRUD request? Our usecase is that we have a cyclic dependency between let's say categories and meta categories. When saving either of them we wanted to build a hook system, which automagically updates meta categories when saving categories and vice versa. Now the problem is, that hooks get triggered in a loop, as one collection saves the other and the other way round. This could be mitigated by specifically saving an entity w/o executing it's hooks, or am I wrong? Have you already encountered this problem? Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @zaunermax — we really appreciate your interest in Payload. Great to hear that you're enjoying working with it. Got a lot more goodness on the way too. What I'd do in this case, is first check if the That way, if the proper relationship already exists, you won't update again needlessly, and then the hooks won't re-run. Just need to introduce some type of loop-breaking logic. That's what I'd do. This is totally a common thing. Need to break the cycle in one way or another. Does that help? |
Beta Was this translation helpful? Give feedback.
Hey @zaunermax — we really appreciate your interest in Payload. Great to hear that you're enjoying working with it. Got a lot more goodness on the way too.
What I'd do in this case, is first check if the
metaCategory
orcategory
already has the relationship that it needs, before actually updating it in your hooks.That way, if the proper relationship already exists, you won't update again needlessly, and then the hooks won't re-run. Just need to introduce some type of loop-breaking logic. That's what I'd do.
This is totally a common thing. Need to break the cycle in one way or another.
Does that help?