# How do I fetch data with M2M relationships?

**URL:** <https://community.directus.com/t/how-do-i-fetch-data-with-m2m-relationships/93>\
**Category:** Help\
**Tags:** data-modeling, api\
**Created:** [April 15, 2025, 3:32pm UTC](https://community.directus.com/t/how-do-i-fetch-data-with-m2m-relationships/93 "2025-04-15T15:32:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonathanwagner](https://sea2.discourse-cdn.com/flex002/user_avatar/community.directus.com/jonathanwagner/32/47_2.png) [@jonathanwagner](https://community.directus.com/u/jonathanwagner)\
**Post date:** [April 15, 2025, 3:32pm UTC](https://community.directus.com/t/how-do-i-fetch-data-with-m2m-relationships/93/1 "2025-04-15T15:32:02Z")

</div>

How do I fetch data with M2M relationships?

---

<div class="post-metadata">

**Author:** ![comfortablycoding](https://sea2.discourse-cdn.com/flex002/user_avatar/community.directus.com/comfortablycoding/32/37_2.png) [@comfortablycoding](https://community.directus.com/u/comfortablycoding)\
**Post date:** [April 22, 2025, 2:12pm UTC](https://community.directus.com/t/how-do-i-fetch-data-with-m2m-relationships/93/2 "2025-04-22T14:12:09Z")

</div>

In Directus, fetching **many-to-many (M2M) relationships** involves understanding how they are structured and how to query them via the **REST** or **GraphQL** API. M2M relationships are configured with a [junction table](https://directus.io/docs/guides/data-model/relationships#many-to-many-m2m) that is exposed at the API level. If we assume the following `ingredients`,`recipes` and `recipes_ingredients` collection exist with an `M2M` field on `recipes` names `ingredients` we can query for the ingredient names as follows:

### **Fetching M2M Relationships via REST API**

To fetch a recipe along with the name of its ingredients:

```http
GET /items/recipes?fields=*,ingredients.ingredients_id.name

```

Where:

- `*` fetches all top level fields
- `ingredients` is the alias set up in the relationship field in `recipes`
- `.ingredients_id.name` fetches the name fields for the related `ingredients` collection only.

* * *

### **Example JSON Response**

```json
{
  "data": [
    {
      "id": 1,
      "name": "Recipe 1",
      "ingredients": [
        {
          "ingredients_id": {
            "name": "Ingredient 1"
          }
        },
        {
          "ingredients_id": {
            "name": "Ingredient 2"
          }
        }
      ]
    }
  ]
}

```

* * *

### **GraphQL Equivalent**

If you’re using GraphQL, the query would look like:

```graphql
query {
  recipes {
    id
    name
    ingredients {
      ingredients_id {
        name
      }
    }
  }
}

```
