# Foreign Key Relations

## Link or Embed Foreign Key Relation

When a resource representation includes a relation with another (foreign) resource, the relation **MUST** be expressed as a link relation or embed the related resource.

### Example

Use:

```javascript
{
  "_links": {
    "author": { "href": "/users/john" }
    ...
  }
  ...
}
```

or:

```javascript
{
  ...
  "_embedded": {
    "author": {
      "_links": { "self": "/users/john" },
      "name": "John Appleseed",
      "email": "john@apple.com"
    }
  }
}
```

instead of:

```javascript
{
  ...
  "authorHref": "/users/john"
}
```

## Nest Foreign Key Relation

If a foreign object has another identifier, but URI or the foreign object isn't a resource, the object **MUST** be nested.

### Example

Use:

```javascript
{
  "author": {
    "id": "1234",
    "name": "John Appleseed",
    "email": "john@apple.com"    
  }
}
```

instead of:

```javascript
{
  "authorId": "1234"
}
```

> NOTE: As a rule of thumb, in an HTTP message body, there **SHOULD NOT** be any field with trailing "\_id," "\_href," "\_url" etc. in its name.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://adidas.gitbook.io/api-guidelines/rest-api-guidelines/message/foreign-key-relations.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
