Is there documentation somewhere for the order in which hooks execute? Specifically between fields and collection hooks.
Example: I have a field called
slug
which uses a
beforeValidate
field hook to format from the title (this is copied from the payload remix example). On that same collection I have a
beforeValidate
collection hook that generates a uriPath using that
slug
field.
Currently I think I'm hitting a race condition in the order those fire. I need the
slug
to be formatted (the field hook) before generating the
uriPath
. I know I could move the
formatSlug
field hook to the collection level but I'd rather understand what is happening.
Here is the source code for the update operation:
https://github.com/payloadcms/payload/blob/master/src/collections/operations/update.ts#L158-L187
are you returning the slugified value from your field hook? You should be able to access that via
data
in your collection beforeValidate function
If I'm reading all the correctly, Field hooks finish in no particular order but Collection hooks should wait for all the Field hooks to finish before running.
I'll need to figure out how to reproduce the issue I was seeing. Naturally it's not happening all the time (hence the wondering about a race condition)
That is correct, field validations run in parallel
@dianoga you might find this discussion relevant
https://github.com/payloadcms/payload/discussions/2785(and an upcoming PR
https://github.com/payloadcms/payload/discussions/2889#discussioncomment-6730791)
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.