How do you make one-to-one and one-to-many and many-to-many in Strapi v3?

Viewed 10
{
  "kind": "collectionType",
  "collectionName": "authors",
  "info": {
    "name": "authors"
  },
  "options": {
    "increments": true,
    "timestamps": true,
    "draftAndPublish": false
  },
  "attributes": {
    "name": {
      "type": "string",
      "required": true
    },
    "dateOfBirth": {
      "type": "date"
    },
    "books": {
      "collection": "books"
    }
  }
}

{
  "kind": "collectionType",
  "collectionName": "admin",
  "info": {
    "name": "admin"
  },
  "options": {
    "increments": true,
    "timestamps": true,
    "draftAndPublish": false
  },
  "attributes": {
    "name": {
      "type": "string",
      "required": true
    },
    "dateOfBirth": {
      "type": "date"
    },
    "section": {
      "model": "section"
    }
  }
}

Looked at the documentation and it doesn't make clear how it works exactly, but I have these two models I found that seem to suggest that model is for one-to-one relations while collection is used for one-to-many relations. Is this the case, I also found plural and singular versions of sections being used, but I don't know if they refer to section the both of them, because I only have a collection named section, and I don't have both "sections" and "section".

{
  "kind": "collectionType",
  "collectionName": "books",
  "info": {
    "name": "books"
  },
  "options": {
    "increments": true,
    "timestamps": true,
    "draftAndPublish": false
  },
  "attributes": {
    "name": {
      "type": "string",
      "required": true
    },
    "sections": {
      "collection": "sections"
    }
  }
}
0 Answers
Related