Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

464
Visualizações
No relational fields in response Strapi v4

I have a problem where none of the relational fields are present in the responses after fetching my data. When I look to the schema of one of my schemas with a relation, I see that the relational fields are present in the attributes object. But still I only get the non-relational fields in my response.

This is one of my schemas

{
  "kind": "collectionType",
  "collectionName": "activities",
  "info": {
    "singularName": "activity",
    "pluralName": "activities",
    "displayName": "activity"
  },
  "options": {
    "draftAndPublish": true
  },
  "pluginOptions": {},
  "attributes": {
    "name": {
      "type": "string"
    },
    "date": {
      "type": "date"
    },
    "subcategory": {
      "type": "relation",
      "relation": "oneToOne",
      "target": "api::subcategory.subcategory"
    },
    "members": {
      "type": "relation",
      "relation": "manyToMany",
      "target": "api::member.member",
      "inversedBy": "activities"
    }
  }
}
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

In Strapi v4 relations are not populated when fetching entries by default.

Explaination:

Queries can accept a populate parameter to explicitly define which fields to populate, with the following syntax:

GET /api/:pluralApiId?populate=field1,field2

Example request: Get books and populate relations with the author's name and address

GET /api/books?populate=author.name,author.address

For convenience, the * wildcard can be used to populate all first-level relations:

Example request: Get all books and populate all their first-level relations

GET /api/books?populate=*

Example request: Get all books and populate with authors and all their relations

GET /api/books?populate[author]=*

Note: Only first-level relations are populated with populate=*. Use the LHS bracket syntax (i.e. [populate]=*) to populate deeper:

Example request: Get all relations nested inside a "navigation" component in the "global" single type

GET /api/global?populate[navigation][populate]=*

Solution:

Change your API url to one of the following and you should be able to see the related fields populated in the response.

GET /api/activities?populate=subcategory,members

OR

GET /api/activities?populate=*

Reference:

  • Relations Population
about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda