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

# FK Strategies

> Foreign key distribution strategies, self-referencing FKs, and strategy configuration.

# FK Strategies

Seedling provides multiple strategies for distributing FK values, handling real-world patterns like Pareto distributions, many-to-many joins, and self-referencing hierarchies.

## Strategies

### Uniform (Default)

Parent rows are selected uniformly at random. Each child row gets a random parent FK.

```yaml theme={null}
orders:
  user_id:
    generator: fk_pool
    params:
      strategy: uniform
```

### Sequential

Parent rows are assigned sequentially. Useful for ordered data like time-series.

```yaml theme={null}
logs:
  session_id:
    generator: fk_pool
    params:
      strategy: sequential
```

### Weighted

Some parent rows receive more children than others. Follows a configurable distribution.

```yaml theme={null}
comments:
  post_id:
    generator: fk_pool
    params:
      strategy: weighted
      distribution:
        - weight: 80  # top 20% of posts get 80% of comments
        - weight: 20
```

### Exclusive

Each child row gets a dedicated parent row (1:1 relationship).

```yaml theme={null}
user_profiles:
  user_id:
    generator: fk_pool
    params:
      strategy: exclusive
```

## Self-Referencing FKs

For tables with self-referencing foreign keys (e.g., `employees.manager_id → employees.id`), Seedling uses a **multi-pass generation** strategy:

1. **Pass 1:** Generate a batch of rows with NULL in the self-FK column
2. **Pass 2:** Assign FK values from pass 1 rows (or earlier pass rows) to fill in references

```yaml theme={null}
employees:
  manager_id:
    generator: self_fk
    params:
      max_depth: 3
      null_probability: 0.2
```

| Parameter          | Description                                 | Default |
| ------------------ | ------------------------------------------- | ------- |
| `max_depth`        | Maximum hierarchy depth                     | `5`     |
| `null_probability` | Probability a row has no parent (top-level) | `0.1`   |
