#How to populate doc in hook?
6 messages · Page 1 of 1 (latest)
Help is on the way! To mark it as solved, use the /solve command. In the meantime, here are some existing threads that may help you:
Documentation:
- Field Hooks - Config Options
- Field Hooks - Config Options - afterChange
- Fields Overview - Field Types - Virtual Fields
Community-Help:
Hello!
You could make a database query to the author collection, passing the ID to get all the information of that author. Otherwise, maybe adding the parameter depth: '2' might be enough.
afterChange: [async ({ doc, req }) => {
const authorData = await req.payload.findByID({
collection: 'authors',
id: doc.author,
})
}],
Hello @fiery lantern , thank you. I was thinking about making separate query to author, but I thought there is a way to populate doc directly. :/ When the post is in status "draft", all fields are populated somehow, but not when published.