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
npx skills add dev-toolings/superpowers-symfony --skill doctrine-relations -a claude-codeWhat 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-code2Manually: put the files in place
~/.claude/skills/doctrine-relations/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/doctrine-relations/
1Skills CLI (Vercel)
npx skills add dev-toolings/superpowers-symfony --skill doctrine-relations -a codex2Manually: put the files in place
.agents/skills/doctrine-relations/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add dev-toolings/superpowers-symfony --skill doctrine-relations -a cursor2Manually: put the files in place
.cursor/skills/doctrine-relations/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install dev-toolings/superpowers-symfony content/skills/doctrine-relations2Manually: put the files in place
.github/skills/doctrine-relations/SKILL.md1Skills CLI (Vercel)
npx skills add dev-toolings/superpowers-symfony --skill doctrine-relations -a gemini-cli2Platform CLI
gemini skills install https://github.com/dev-toolings/superpowers-symfony --path content/skills/doctrine-relationsManually: put the files in place
.devin/skills/doctrine-relations/SKILL.mdThe legacy .windsurf/skills/ path still works
Claude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
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