> ## Documentation Index
> Fetch the complete documentation index at: https://docs.occtoo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# occtoo relations

> Manage relations: the links between the cards of two card definitions

A relation links the cards of two card definitions. A source card is related to the target cards whose value of one property matches its own. Segments and destination endpoints can follow relations.

## List and show

```bash theme={null}
occtoo relations list --source-card products
occtoo relations show productVariants
```

| Flag (`list`) | Description |
| - | - |
| `--name <NAME>` | Only relations whose name contains this text |
| `--source-card <CARD>` | Only relations from this card definition |
| `--target-card <CARD>` | Only relations to this card definition |
| `--status <STATUS>` | `initializing`, `updating` or `active` |
| `--limit <LIMIT>` | Maximum number to return. Default `100` |

## Create a relation

```bash theme={null}
occtoo relations create
occtoo relations create --file relation.json
```

In a terminal, you pick both cards and the properties to match. Otherwise, pass JSON. `description`, `tags`, the display names and `order` are optional:

```json theme={null}
{
  "id": "productVariants",
  "name": "Product variants",
  "sourceCardId": "products",
  "targetCardId": "variants",
  "match": { "sourceProperty": "sku", "targetProperty": "parentSku" },
  "sourceDisplayName": "Variants",
  "targetDisplayName": "Variant of",
  "order": { "type": "BasedOnTargetProperty", "property": "position" }
}
```

* Both card definitions have to be `Active`.
* A match property is a `Text` or `List` card property, or `id` for the id of the card. Both sides can't be `List`.
* Occtoo builds the links in the background. A new relation is `Initializing`, or `Updating` after a new match, until it is `Active`.

To see what a relation links to, use [`occtoo cards entries related`](https://docs.occtoo.com/cli/commands/cards#find-related-entries).

## Edit a relation

```bash theme={null}
occtoo relations edit productVariants
echo '{"name": "Variants", "match": {"sourceProperty": "sku", "targetProperty": "parent"}}' | occtoo relations edit productVariants
```

In a terminal, the CLI prompts for the name and description. In JSON, every field is optional, and a field you leave out stays as it is.

## Delete a relation

```bash theme={null}
occtoo relations delete productVariants --yes
```

Deletes a relation for good. It is refused while a destination endpoint or a segment uses it.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.