# PipelineItemLabel

## Description

PipelineItemLabel is the many-to-many join record that pairs a PipelineItem with a PipelineLabel. The combination of (itemId, labelId) is unique — enforced by a unique index, with the attach command returning a friendly LABEL_ALREADY_ATTACHED error before the index is hit. The pair is destroyed when either the item is deleted, the label is deleted, or the label is explicitly detached from the item.

## Domain Model Definitions

### Model type

Standard

### Command Definitions

- [AttachLabelToPipelineItem](../command/AttachLabelToPipelineItem.md) - Attach an existing label to an item
- [DetachLabelFromPipelineItem](../command/DetachLabelFromPipelineItem.md) - Detach a label from an item

### Query Definitions

- [ListPipelineLabelsByItem](../query/ListPipelineLabelsByItem.md) - List all labels currently attached to an item, ordered by label name

### Models

- PipelineItemLabel

### Invariants

- PipelineItem ID is required and must reference an existing item
- PipelineLabel ID is required and must reference an existing label
- The label must belong to the same pipeline as the item
- The combination of (itemId, labelId) must be unique (backed by a unique index)
- `createdAt` records when the label was attached and never changes

### Relationships

- **Belongs To PipelineItem**: Each PipelineItemLabel belongs to an item via `itemId`
- **Belongs To PipelineLabel**: Each PipelineItemLabel belongs to a label via `labelId`
