Skip to main content
skill CX Codex

doctrine-relations — Claude Code skill: Doctrine entity relationships

Skill guides you through defining Doctrine relationships (OneToMany, ManyToMany, ManyToOne) with correct owning and inverse sides, cascade strategies, and N+1 query prevention.

MIT ★ 234 updated 2026-10-05

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add dev-toolings/superpowers-symfony --skill doctrine-relations -a claude-code
Open on GitHub

What doctrine-relations does

Doctrine Relations sets patterns for entity relationships. The skill helps you pick the owning side (holds the foreign key) and the inverse side, initialize collections with ArrayCollection, write addX() and removeX() helpers that keep both sides in sync. It advises when to use cascade: ['persist'] for aggregates saved together and orphanRemoval: true only for true composition.

For large collections, it suggests fetch: 'EXTRA_LAZY' or checking membership from the owning side. Adds fetch joins in hot paths to avoid N+1 queries. When your project spans multiple entity managers, the skill ensures each entity stays in one manager and helps you fetch repositories through ManagerRegistry.

The skill uses Read, Glob, Grep, Write, Edit and Bash tools to inspect mappings, find N+1 hotspots, edit entities, and run doctrine:schema:validate.

What it helps with

  • decide which side owns a relationship and set up inversedBy and mappedBy
  • initialize collections and keep both sides synchronized
  • prevent N+1 queries with fetch joins
  • configure cascade operations and orphan removal
  • work across multiple entity managers

Example prompts for the agent

  • Set up a ManyToOne relationship between Post and Author with the right owning side
  • How do I avoid N+1 queries when loading a large collection of comments for an article?
  • I need to split entities across two entity managers — what's the right way to define relationships?

How to install doctrine-relations

1Skills CLI (Vercel)

npx skills add dev-toolings/superpowers-symfony --skill doctrine-relations -a claude-code

2Manually: put the files in place

~/.claude/skills/doctrine-relations/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/doctrine-relations/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about doctrine-relations

How do I install doctrine-relations in Claude Code?

Run npx skills add dev-toolings/superpowers-symfony --skill doctrine-relations -a claude-code, then open ~/.claude/skills/doctrine-relations/SKILL.md.

What does doctrine-relations do?

The skill helps you define Doctrine relationships (ManyToOne, OneToMany, ManyToMany), choose the correct owning side, set up cascade strategies, and protect your code from N+1 queries through fetch joins and optimized loading tactics.

Which tools does the skill use?

It uses Read, Glob, Grep to search and analyze mappings, Write and Edit to modify entities, and Bash to run validation commands like doctrine:schema:validate.

Source text

SKILL.md · MIT
---
name: doctrine-relations
description: Define Doctrine entity relationships (OneToMany, ManyToMany, ManyToOne); configure cascade, orphan removal, multiple entity managers; prevent N+1 queries
capabilities: [read, search, edit, shell]
tags: [doctrine]
# projected by `bun run build` — do not edit by hand
allowed-tools:
  - Read
  - Glob
  - Grep
  - Write
  - Edit
  - Bash
---

# Doctrine Relations (Symfony)

## Use when
- Mapping a `ManyToOne`, `OneToMany`, `ManyToMany` or `OneToOne` and choosing the owning side.
- Deciding between `cascade` and `orphanRemoval` for child entities.
- A relation does not persist (only the inverse side was set), or `contains()` is slow on a large inverse collection.
- Splitting entities across several entity managers.

## Default workflow
1. Pick the owning side (holds the foreign key, `ManyToOne` with `inversedBy`) and the inverse side (`OneToMany` with `mappedBy`).
2. Initialize collections with `ArrayCollection` in the constructor, and write `addX()` and `removeX()` helpers that keep both sides in sync.
3. Use `cascade: ['persist']` for aggregates saved together, and `orphanRemoval: true` only for true composition.
4. Mark large inverse collections `fetch: 'EXTRA_LAZY'`, or test membership from the owning side.
5. Add fetch joins where a use case reads the relation, to avoid N+1 queries.
6. With several entity managers, keep each entity set in one manager and fetch repositories through `ManagerRegistry`.

## Guardrails
- Doctrine persists what the owning side holds: always set the `ManyToOne` reference.
- Avoid `cascade: ['remove']` on large collections (one DELETE per row), and never use `orphanRemoval` on shared entities.
- A relation cannot span two entity managers.
- For a non-default entity manager, fetch repositories with `ManagerRegistry::getRepository(Entity::class, 'name')`.

## Progressive disclosure
- Use this file for execution posture and risk controls.
- Open references when deep implementation details are needed.

## Output contract
- Entity mappings with the owning and inverse sides, cascade and orphan decisions.
- Fetch strategy for large collections and hot paths.
- Result of `doctrine:schema:validate`.

## References
- `reference.md`

© dev-toolings · MIT · dev-toolings/superpowers-symfony

Similar skills

All skills for Backend and APIs →
php-symfony official github php-symfony — a GitHub Copilot rule that keeps code generation aligned with official Symfony Best Practices. It kicks in for PHP, YAML, XML and Twig files as the assistant completes controllers, configs and templates. CX Codex +1 ★ 41,430repo stars symfony-specialist VoltAgent Community symfony-specialist — a Claude subagent for Symfony 6.4, 7.x and 8.0 work: Doctrine entities, Messenger async processing, API Platform resources. CX Codex ★ 26,718repo stars eloquent-best-practices iSerter eloquent-best-practices provides guidelines for Laravel Eloquent ORM, from eager loading relationships to mass assignment guards. Useful for keeping queries fast and preventing N+1 problems. CX Codex +1 1,300installs prisma-driver-adapter-implementation prisma prisma-driver-adapter-implementation is a Claude Code skill and reference guide for implementing SQL adapters in Prisma ORM 7. It covers transactions, savepoints, value mapping, and database errors. CX Codex +1 425,600installs django-perf-review getsentry The django-perf-review skill reviews Django code for N+1 queries, unbounded querysets and missing indexes. Useful before a release or when a page slows down on large tables. CX Codex +1 3,200installs sqlalchemy-alembic-expert-best-practices-code-review wispbit sqlalchemy-alembic-expert-best-practices-code-review is a Claude Code skill for writing and reviewing SQLAlchemy models, Alembic migrations, and database queries. It activates around schema changes and query tuning. CX Codex +1 2,200installs

From the same set51

The whole set →
doctrine-migrations Create and review Doctrine migrations, prepare rollbacks, and check pending changes before deployment. Useful when a Symfony app’s entity mapping changes. CX Codex +1 ★ 234repo stars symfony-messenger A skill for async message handling with Symfony Messenger: configures transports, handlers, and retry strategies. CX Codex +1 ★ 234repo stars api-platform-security api-platform-security secures API Platform operations with security expressions, voters, and validation-phase access checks in Symfony. CX Codex +1 ★ 234repo stars e2e-panther-playwright The e2e-panther-playwright skill guides Symfony E2E tests with Panther for browser flows and Playwright for more involved cases. Use it when JavaScript behavior is beyond what WebTestCase can observe. CX Codex +1 ★ 234repo stars doctrine-fetch-modes doctrine-fetch-modes guides Doctrine ORM and DBAL 4 query optimization in Symfony. Fixes N+1 queries, configures lazy loading, and implements DTO hydration. CX Codex +1 ★ 234repo stars api-platform-resources api-platform-resources is a Claude Code skill for configuring API Platform resources for REST and GraphQL. It activates for resource creation and changes to operations, pagination, or OpenAPI docs. CX Codex +1 ★ 234repo stars messenger-retry-failures messenger-retry-failures sorts out failed Symfony Messenger handlers: whether a message deserves another attempt, when it goes straight to the failure transport, and how to pull it back. CX Codex +1 ★ 234repo stars api-platform-state-providers Configures API Platform State Providers and Processors in Symfony. It helps decouple data retrieval and persistence from Doctrine entities. CX Codex +1 ★ 234repo stars

Project sponsors

Companies that keep this analytics open