joincollectionsrelationshipone-to-manydirectus

Combining Collections in Directus


I've setup a Directus CMS project with 3 collections as follows:

  1. Actors
  2. Movies
  3. TV Shows

I'd like to associate Movies and TV Shows with Actors in a multi-select ordered list. I've tried looking at the one-to-many relationship and some others and can't seem to figure out how to build this. Ideally I would like it to look roughly like:

Do I need an intermediary junction collection? Am I missing something obvious here?

From initial impressions Directus looks to be an awesome CMS!


Solution

  • you were on the right track, but the relationship type you are looking for is a "many-to-many" (or M2M). This is because a movie can have many actors, and actors can be in many movies.

    You can see the Directus documentation for this relationship setup here:

    https://directus.io/docs/guides/data-model/relationships#many-to-many-m2m

    You will add two junction tables, something like actor_movies and actor_tv_shows, each with a schema like this:

    Therefore, each record in these tables link an actor to a Movie or TV Show.