doctrine-patterns

Standardize Doctrine ORM entity mappings, queries, and migrations for Symfony projects.

9|1|Updated Jun 16, 2026
One-click install
npx skills add https://github.com/AratKruglik/antigravity-sdlc --skill doctrine-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: doctrine-patterns
Source: https://github.com/AratKruglik/antigravity-sdlc/tree/main/plugins/symfony-plugin/skills/doctrine-patterns
Command: npx skills add https://github.com/AratKruglik/antigravity-sdlc --skill doctrine-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Doctrine ORM best practices for Symfony help teams avoid common pitfalls such as N+1 queries, brittle migrations, and inconsistent entity mappings by codifying standards around mapping, queries, and migrations.

Core Features & Use Cases

  • Entity mapping with attributes: keep mapping as the source of truth and generate migrations from it.
  • Parameterized DQL / QueryBuilder: promote safe, injective queries and prevent SQL injection.
  • N+1 prevention: use fetch joins and proper fetch strategies.
  • Relations management: configure cascade, fetch, and orphanRemoval for robust aggregates.
  • Migrations & lifecycle events: automate migrations with lifecycle hooks for auditability.

Quick Start

Start applying these patterns by configuring your Symfony entities with attributes, validating queries, and enabling migrations to keep schema in sync.

Frequently Asked Questions about doctrine-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix N+1 query issues in Doctrine ORM with Symfony?

Prevent Doctrine ORM N+1 queries in Symfony by applying fetch joins and proper fetch strategies within your repositories. Configuring relation fetch modes correctly reduces redundant queries and optimizes data loading.

What is the best way to keep Doctrine migrations in sync with entity mappings?

Keep Doctrine migrations in sync by using attribute-based entity mappings as the source of truth. You generate migrations directly from mapping attributes and automate their execution using lifecycle events for data integrity.

How do I write parameterized DQL queries in Symfony repositories?

Write parameterized DQL queries in Symfony repositories using QueryBuilder to bind input values securely. This approach promotes safe, injective queries and prevents SQL injection vulnerabilities in your application.

How should I configure cascade and orphanRemoval for Doctrine entity relations?

Configure cascade, fetch, and orphanRemoval on Doctrine entity relations to maintain robust aggregates. Setting these attributes correctly ensures dependent entities are properly persisted and removed during lifecycle events.

Do I need attribute-based mappings for Symfony Doctrine entities?

Attribute-based mappings are enforced to keep entity configuration as the source of truth and generate migrations accurately. Standardizing on attributes ensures schema consistency and data integrity across Symfony projects.