What are your takes on o2o relations?

Hi everyone,

I’m curious about the most “Directussy” way to handle a one-to-one-like relation.

Example: collections restaurants and rocations. Each restaurant has exactly one location (restaurant.location).

  • Using O2M returns an array with one item via the API, which feels awkward.

  • Using M2O returns a single object, this makes locations the “parent” and cascade deletion is available only for restaurants.

What does the team/community think is the cleanest, most Directus-native approach for this pattern?

1 Like

I’d set up a location m2o column from restaurant.locationlocations.id, then make the location column unique so a location can only ever be used on a restaurant once. That also means you can cascade delete the location when deleting the restaurant.

If you have no other planned relationships to locations, you could also consider just making them primitive fields directly on the restaurant, but that’s a preference not a requirement