I have a "Users" collection where every user has an additional internal ID. I want to make a call to an external API with that ID and populate the items of a select field based on the response. I think this is do-able, but I'm blanking on how 😄
I'm thinking of using afterRead?
{
name: 'events',
maxDepth: 0,
type: 'relationship',
relationTo: 'events',
hasMany: true,
access: {
create: () => false,
update: () => false,
},
admin: {
readOnly: true,
},
hooks: {
beforeChange: [({ siblingData }) => {
// Mutate the sibling data to prevent DB storage
// eslint-disable-next-line no-param-reassign
siblingData.events = undefined;
}],
afterRead: [getAllEvents],
},
},
But im not sure why we need to mutate the sibling data
or if that was only for that example
Hmmm that runs on every item in the collection
Was hoping for it to run only during editing
Do you think I'm going about it incorrectly?
i cant test rn but im pretty sure in those functions you have access to the full
req
from express
and im pretty sure that object contains something related to what API is being used/invoked and if it's admin panel?
i cant recall right now, can look later for you
Star
Discord
online
Get dedicated engineering support directly from the Payload team.