Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Automatically update relationship field

default discord avatar
pgrts2 years ago
1

Hi, i have a collection ‘layout’ with a block ‘review’. The review block has a relationship field ‘items’ to a collection called 'reviewItems'.



I want the relationship field 'items' to be always up to date with all items from the 'reviewItems' collection. I partially managed that by fetching all reviewItems in the

defaultValue

option. However, if i add more items to the reviewItems collection, i will have to add these manually.



I want to achieve this because i’ll be using the review block on multiple pages and it has to contain the same items on every page. Thanks!



TLDR: Is it possible to make a relationship field that automatically contains all items from a collection.

  • default discord avatar
    jessrynkarlast year

    Hi

    @936926437473144864

    you could add a field hook that makes a request your

    reviewItems

    collection and returns all items. There is more info on field hooks here

    https://payloadcms.com/docs/hooks/fields

    Let me know if you still need help here!

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.