# Feature FND-271 - Use multiple categories in the data model

Project: Stream workspace foundations
Status: needs review
URL: https://community.openproject.org/work_packages/FND-271

## Planning

| Attribute | Value |
| --- | --- |
| Date |  |
| Priority | Medium |
| Target versions | 18.1.0 |
| Sprint |  |
| Backlog bucket |  |
| Votes |  |
| List |  |
| Roadmap |  |
| Relevance |  |

## OPEN POINTS / FEEDBACK

_No work packages_

## Features and Chunks

| ID | Subject | Type | Status | Assignee | Target versions | Spent time |
| --- | --- | --- | --- | --- | --- | --- |
| FND-270 | Create data model for representing multiple categories per WP | Implementation | needs review |  | 18.1.0 |  |
| FND-272 | Mirror all WorkPackage.category writes to categories table | Implementation | needs review |  | 18.1.0 |  |
| FND-281 | Implement code-level setting and feature flag for multiple categories | Implementation | needs review |  | 18.1.0 |  |

## Bugs and other work packages

_No work packages_

## Technical Details

| Attribute | Value |
| --- | --- |
| Module |  |
| Feature Flag |  |
| Requires doc change | No |
| Enterprise plan |  |

## Details

| Attribute | Value |
| --- | --- |
| Pull preview |  |
| Mockups |  |
| Accessibility | No |

## People

| Attribute | Value |
| --- | --- |
| Assignee |  |
| Accountable |  |
| Product manager |  |
| Feature Lead |  |
| Developers |  |
| Designer |  |
| Ordered by |  |
| Signed off by |  |
| Interest by |  |

## Estimates and progress

| Attribute | Value |
| --- | --- |
| PD (min) |  |
| PD (max) |  |
| Work |  |
| Labor costs |  |

## Description

**As a** developer of OpenProject or of an extension  
**I want to** store several categories per work package next to the single category  
**so that** the other subsystems can move to the new model step by step without a behavior change.

**Acceptance criteria**

  - A join table stores the categories of each work package. A category occurs at most once per work package.

  - A data migration copies every existing category into the join table. After the migration, the join table and `category_id` agree for every work package.

  - Every write of categories updates the join table and `work_packages.category_id` in the same transaction. `category_id` holds the first category in alphabetical order.

  - A write to the old single category is mirrored into the join table.

  - Only categories of the work package's project can be set.

  - With multiple categories off, a work package has at most one category.

  - A code-level setting and a feature flag control multiple categories. Both are off by default.

  - Users see no change in the UI or in the API.

**Technical notes**

  - Ship the backfill and the mirror in the same PR. Otherwise a write between two deploys makes the join table stale. Versions did this in PR <mention class="mention" data-id="23946" data-type="work_package" data-text="#23946">#23946</mention>.

  - Raw SQL writes skip model callbacks. They must update both stores directly (for example `Category#destroy`).

  - Reference: `WorkPackage::Categories` and `persist_category_associations` in <https://github.com/opf/openproject/pull/24620>.

  - Analog: <mention class="mention" data-id="COMMS-847" data-type="work_package" data-text="#COMMS-847">#COMMS-847</mention>, <mention class="mention" data-id="COMMS-846" data-type="work_package" data-text="#COMMS-846">#COMMS-846</mention>, <mention class="mention" data-id="COMMS-853" data-type="work_package" data-text="#COMMS-853">#COMMS-853</mention>, <mention class="mention" data-id="COMMS-873" data-type="work_package" data-text="#COMMS-873">#COMMS-873</mention>.

**Out of scope**
