mcpField
D
doctrine-relations

doctrine-relations

github.com/dev-toolingsDevelopment22794 installsUpdated 3w ago
Repository

About doctrine-relations

A Symfony and Doctrine skill for mapping entity relations and managing their persistence behavior. It guides owning-side decisions, cascading, orphan removal, collection loading, and multiple entity managers.

Key features

  1. 01Map owning and inverse sides
  2. 02Keep bidirectional collections in sync
  3. 03Choose cascade and orphan removal
  4. 04Handle large collections and fetch joins
  5. 05Work with multiple entity managers

Use cases

  1. 01Map a new Doctrine relation
  2. 02Fix relations that do not persist
  3. 03Choose removal behavior for child entities
  4. 04Access repositories across entity managers

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/dev-toolings/superpowers-symfony --skill doctrine-relations

After installing, type/doctrine-relationsin Claude Code to confirm it loaded.

Bundled filesreference.md

Details

From the project README

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

Comments

Markdown supported