Relation queries

By default, none related records are fetched for a query. With include, related records can be fetched into the result set together. The nested argument inside include, behaves like findMany's argument or findUnique's argument depending on whether the relation is single or many.

const { data: artists } = await teo.artist.findMany({
  include: {
    songs: {
      where: {
        name: { startsWith: 'Fairy' }
      }
    },
  }
})
Hide HTTP response
[
  {
    "id": 4,
    "name": "Angela Peterson",
    "age": 23,
    "songs": [
      {
        "id": 2,
        "name": "Fairy Tale",
        "published": true
      }
    ]
  },
  {
    "id": 5,
    "name": "Tony Justin",
    "age": 27,
    "songs": []
  }
]