Pottr/Docs
Topic:Relationships & Expansion
Core Concepts
.md

Relationships & Expansion

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).

schema-definition.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:

GET /wp-json/pottr/v1/collections/tasks?expand=project_id
{
  "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 }
}

Single-Level Expansion

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