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.

Are two way relations a thing in PayloadCMS?

default discord avatar
rxbbxss9 months ago
2

EG: If I have a collection, say SportsTeams, with a relation to another collection Matches, is there a reccomended way of setting up so the Matches know which Sports teams they belong to, and the sports teams know which matches they have?



I might be missing something obvious here.



Ended up using a different db setup for that project as there were going to be a lot of two way bindings! Sorry forgot to mark this as closed



... And I'm not sure how to tbh!

  • default discord avatar
    paradox5270last year

    Personally I would have a property “teams” in Matches collection that stores array of id (has many) relation to SportsTeams, then turn on indexing for the “teams” field. That way when querying for matches a team has played, you simply use where: {teams: {contains: team_id}}

  • discord user avatar
    seanzubrickas
    last year

    Hey

    @129037731274817537

    did you try the suggestion

    @727901959537033246

    made here? Let us know if that works for you or if you need additional help here. Thanks!



    No worries! I'll take care of it

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.