# Relationships & Expansion

> Connecting entities across collections and resolving linked records with single-level relation expansion.

- **Category:** Core Concepts
- **Canonical Guide:** https://pottr.tangble.com/docs/relationships

---

>
Connecting entities across collections and resolving linked records with single-level relation expansion.

## Declaring a Relation Field

To link one collection to another, declare a field with `type: "relation"` and specify the `target_collection` slug. By convention, relation field keys should use the `_id` suffix (e.g. `project_id`, `author_id`).

**File: `schema-definition.json`**

```json
{
  "key": "project_id",
  "name": "Project",
  "type": "relation",
  "target_collection": "project",
  "required": true
}
```

## Relation Expansion (`?expand`)

By default, querying a collection returns the numeric ID stored in the relation field. When your frontend needs the related data, append `?expand=field_key` to inline the full related entry in a single HTTP request:

**File: `GET /wp-json/pottr/v1/collections/tasks?expand=project_id`**

```json
{
  "data": [
    {
      "id": 42,
      "title": "Write integration tests",
      "project_id": {
        "id": 7,
        "collection": "project",
        "data": {
          "title": "Q3 Mobile App Launch",
          "status": "in_progress"
        },
        "created_at": "2026-05-01 10:00:00",
        "updated_at": "2026-05-03 14:22:00"
      }
    }
  ],
  "meta": { "total": 1, "limit": 20, "offset": 0, "has_more": false }
}
```

<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
Single-Level Expansion

Relation expansion is single-level. Pottr does not perform recursive nested expansions to ensure predictable performance and prevent circular dependency loops.
