Hello,
Currently have a "working" beforeDelete hook which iterates over the Pages collection however I would also like to show a warning if a related topic is included within a global field..
collection: 'pages'
seems to be the line i need to change but I can't find any docs on how to access globals within the
req.payload
object
Any help would be appreciated
export const checkTopicsNotInReleatedPagesOrSubNav: BeforeDeleteHook = async ({ req, id }) => {
console.log('checkTopicsNotInReleatedPagesOrSubNav fired', id)
console.log('req.payload:', req.payload)
const result = await req.payload.find({
collection: 'pages',
limit: 100,
depth: 2,
where: {
// 'globals.subNav.topic': { equals: id },
'topics': { equals: id },
},
});
Hey @jamesryan, welcome! The function you're looking for is
findGlobal
. Docs are here:
https://payloadcms.com/docs/local-api/overview#globals