Understanding & using Relations in Strapi

In this article, we will look into the relational fields in Strapi to see how we can utilize them to establish relationships in our models


This is a companion discussion topic for the original entry at https://strapi.io/blog/understanding-and-using-relations-in-strapi

One-to-Many This relation involves a table pointing to several or many tables.”: I think “One-to-Many” means a table pointing to many recored in another table, not “…to several or many tables”. Refer: One-to-many (data model) - Wikipedia

“The Comment model and the Answer model have a one-to-one relationship. A comment has one answer.”: The relation between Comment and Answer should be One-Way relationship, because of there is no point back to the “pointing” column in answer model. Look the source files:

comment.settings.json

...
"attributes": {
    "cText": {
      "type": "text"
    },
    "answer": {
      "model": "answer"
    },
    "user": {
      "type": "string"
    }
  }
...

answer.settings.json

...
"attributes": {
    "aText": {
      "type": "text"
    },
    "user": {
      "type": "string"
    },
    "question": {
      "via": "answers",
      "model": "question"
    }
  }
...