I'm writing a custom field with an AfterRead field hook (not collection hook), and I want to access the collection this hook is being run from. When I try to access
req.collection
from the hook's arguments, it's undefined. When I try using collection hooks instead, the
req.collection
is NOT undefined as expected.
Is there a way to access the collection in field hooks?
Looking into this right now!
@bombnp Hm I cannot reproduce it. Tried adding an afterRead hook to a field, and
req.collection
works perfectly.
Could you try creating a minimal reproduction using this guide:
https://github.com/payloadcms/payload/blob/master/.github/reproduction-guide.md?
Specifically this is what I tried, and req.collection does exist here
Wth I tried to create a minimal reproduction repo with the same code and it works fine.
Then, I went back to my own project with the same code and it somehow works fine now without any changes. Maybe some shenanigans with nodemon i guess. Sorry for wasting your time
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.