Requesting with relationships

System Information
  • Strapi Version: 4.5.4

This is quite a simple question, but I don’t really understand how the Strapi API deals with relationships

I have a single type “training” that has many “modules”.
Therefore, I configured a One-To-Many relationship between the Training single type and the Modules collection.

Indeed, the generated documentation indicates that the /training endpoint shows a modules array, each module being presented with its fields.

However, querying this endpoint, the modules array does exist but appears empty.

Of course, modules data does exist.

I checked the permissions, both for the modules collection and the training single type.

Did I miss something?


Maybe your modules content-type uses draft/publish feature and these are NOT published? If modules are not published then these will not be visible when accessing /training

Thanks :slight_smile:
I had forgotten to check this.

But, modules are published…

Can you attach the model settings files for training and modules?

It seems there is only this line in Training to hold the relationship:

    "modules": {
      "collection": "modules"
    },

This is formation.settings.json (aka training) :

{
  "kind": "singleType",
  "collectionName": "formation",
  "info": {
    "name": "formation",
    "description": ""
  },
  "options": {
    "increments": true,
    "timestamps": true,
    "draftAndPublish": false
  },
  "attributes": {
    "titre": {
      "type": "string",
      "required": true
    },
    "seo": {
      "type": "component",
      "repeatable": false,
      "component": "meta.seo"
    },
    "competencesTitre": {
      "type": "string"
    },
    "atouts": {
      "type": "component",
      "repeatable": true,
      "component": "interface.atout"
    },
    "moduleIntros": {
      "type": "component",
      "repeatable": true,
      "component": "global.module-intro"
    },
    "modules": {
      "collection": "modules"
    },
    "competences": {
      "type": "component",
      "repeatable": true,
      "component": "global.module-intro"
    },
    "candidater_CTA": {
      "type": "string"
    },
    "image": {
      "model": "file",
      "via": "related",
      "allowedTypes": [
        "files",
        "images",
        "videos"
      ],
      "plugin": "upload",
      "required": true
    }
  }
}

and modules.settings.json :

{
  "kind": "collectionType",
  "collectionName": "modules",
  "info": {
    "name": "modules",
    "description": ""
  },
  "options": {
    "increments": true,
    "timestamps": true,
    "draftAndPublish": true
  },
  "attributes": {
    "titre": {
      "type": "string"
    },
    "type": {
      "type": "enumeration",
      "enum": [
        "transverse",
        "professionalisation"
      ],
      "required": true
    },
    "resume": {
      "type": "text"
    },
    "heures": {
      "type": "integer"
    },
    "ues": {
      "type": "component",
      "repeatable": true,
      "component": "global.module-intro"
    },
    "ordre": {
      "type": "decimal"
    }
  }
}