# Relationships

Source: https://docs.rushdb.com/learn/relationships/

Relationships connect RushDB records into a traversable graph. They are named, directed edges between records — optionally carrying their own [properties](./relationship-properties.mdx) — not foreign-key columns or application-side joins.

You can create relationships explicitly, generate them automatically from nested JSON imports, connect large datasets by matching keys, and filter records by traversing one or more hops inside a `where` clause. Multi-hop traversal is expressed with `$relation.hops` and cycle detection with `$cycle` — see [Where Operators](../search-query/where-operators.md#variable-length-traversal-hops).

## Choose a workflow

| Goal                                                  | Guide                                                                                      |
| ----------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| Attach or detach individual record pairs              | [Connect Records](./connect-records.mdx)                                    |
| Connect many records by matching keys                 | [Bulk Relationships](./bulk-relationships.mdx)                              |
| Store and query data on the edges themselves          | [Relationship Properties](./relationship-properties.mdx)                    |
| Review and approve inferred graph structure           | [Suggested Patterns](./suggested-patterns.mdx)                              |
| Create parent-child edges while importing nested JSON | [Import Data](../records-and-queries/import-data.mdx)                                      |
| Filter through related records                        | [Relationship Traversal](../records-and-queries/find-and-query.mdx#relationship-traversal) |

## Relationship sources

| Source                         | What it creates                                                               |
| ------------------------------ | ----------------------------------------------------------------------------- |
| Nested JSON import             | Default parent-to-child edges as RushDB decomposes the payload                |
| `attach` / `detach`            | Explicit edges between known record IDs                                       |
| Bulk relationship APIs         | Edges between matching source and target records                              |
| Approved relationship patterns | Explicit edges inferred from schema structure and reviewed before application |

Relationship types and direction are optional when traversing broadly and explicit when your query needs a specific edge contract.

## See also
- [Records & Queries](../records-and-queries/index.mdx) — store and retrieve the records relationships connect
- [Labeled Meta Property Graph](../records-and-queries/labeled-meta-property-graph.mdx) — understand record, property, and relationship layers together
- [SearchQuery Reference](../search-query/search-query.md) — full traversal syntax, including multi-hop (`$relation.hops`) and cycle (`$cycle`) matching
