doctrine-relations

Installation
SKILL.md

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.
Installs
76
GitHub Stars
224
First Seen
Sep 17, 2026