Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strapi v4: no relational fields when populating

I'm trying to populate a specific relation, using the relation name (categories) in combination with the populate parameter but it doesn't populate the categories.

When I look at my schema, I see that the relational field is present in the attributes object. But I still only get the non-relational fields in my response.

I tried every combination mentioned on the Strapi documentation but none of them worked.

The find permission is also enabled for the content-types that are being populated which in this case is categories.

/api/products?populate=*
/api/products?populate[0]=categories
/api/products?populate[categories]=*

My Product schema

{
  "kind": "collectionType",
  "collectionName": "products",
  "info": {
    "singularName": "product",
    "pluralName": "products",
    "displayName": "Product",
    "description": ""
  },
  "options": {
    "draftAndPublish": true
  },
  "pluginOptions": {},
  "attributes": {
    "title": {
      "type": "string"
    },
    "images": {
      "type": "media",
      "multiple": true,
      "required": false,
      "allowedTypes": [
        "images"
      ]
    },
    "categories": {
      "type": "relation",
      "relation": "oneToMany",
      "target": "api::category.category"
    }
  }
}

System

  • Strapi version: 4.1.8
  • NPM version: 8.3.2
  • Node.js version: 16.13.2
  • Database: MySQL
like image 329
shahrooz Avatar asked Sep 16 '25 22:09

shahrooz


1 Answers

You need to enable find permission on the product as well. You have to set the find permission on all the relationships (or sub-tables).

Use the "role" option.

like image 61
Young Kwon Avatar answered Sep 19 '25 08:09

Young Kwon