Model Relations

Overview

You can use hasMany and belongsTo field to create relations between models.

For example, our demo server has the following relations defined:

mockend.yml
models:
  Post:
    hasMany: [Comment]
  Comment:
    belongsTo: [Post]

REST API

Considering our previous example, a postId foreign key will be automatically created.

You can then use postId_eq=:id to query nested resources. For example, to get all comments for a post:

https://mockend.com/mockend/demo/comments?postId_eq=1 (opens in a new tab)

GraphQL API

In GraphQL, post and comments fields will be created to query parent/children resources.

For example:

{
  post(id: 1) {
    title
    comments {
      body
    }
  }
}

Run example query (opens in a new tab)