agentsclimarketplace

Doctrine orm patterns

Skill ekut/claude-code-php-toolkit/skills/doctrine-orm-patterns

Use this skill when designing Doctrine ORM entities, mapping relationships, writing DQL/QueryBuilder queries, managing migrations, or optimizing database performance. Covers Doctrine ORM 3.x with PHP 8.1+ attributes.From its SKILL.md

Install
npx -y skills add ekut/claude-code-php-toolkit --skill doctrine-orm-patterns

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 5 stars5 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

3.5 KB, as published. Nobody here has run it

Doctrine ORM Patterns

Patterns for Doctrine ORM 3.x targeting PHP 8.1+ with native attribute mapping. Covers entity design, relationships, queries, migrations, and performance tuning for MySQL and PostgreSQL.

When to Activate

  • Designing or modifying Doctrine ORM entities
  • Mapping relationships (OneToMany, ManyToOne, ManyToMany, OneToOne)
  • Writing DQL queries or using QueryBuilder
  • Managing database migrations (Doctrine Migrations)
  • Preventing N+1 queries and optimizing read/write paths
  • Configuring second-level cache or batch processing

Module Index

TopicFileUse when…
Entity Designentities.mdMapping entities, columns, types, embeddables, inheritance
Relationshipsrelationships.mdOneToMany, ManyToOne, ManyToMany, cascade, orphan removal
Queriesqueries.mdDQL, QueryBuilder, native SQL, projections, pagination
Migrationsmigrations.mdCreating, running, rolling back, zero-downtime strategies
Performanceperformance.mdN+1 prevention, batch processing, caching, indexing

Project Structure

src/
├── Entity/              # Doctrine entities (one class per file)
├── Repository/          # Custom repository classes
├── Migration/           # Generated migration files (via doctrine:migrations)
└── Embeddable/          # Value objects mapped as embeddables

config/
└── packages/
    └── doctrine.yaml    # Connection, mapping, and cache config

Anti-Patterns

  • Public entity properties — use readonly or getter methods; entities are not DTOs
  • Business logic in entities — keep entities focused on state and invariants, not orchestration
  • EAGER fetch on collections — causes N+1; use LAZY + explicit JOIN FETCH in queries
  • Bidirectional relationships everywhere — only add the inverse side when you actually query from that direction
  • Auto-DDL in production — never use auto_generate_proxy_classes: true or schema:update --force in production; use migrations
  • Entity manager in entities — entities must not depend on the EntityManager; use services
  • Missing indexes on foreign keys — Doctrine does not auto-create indexes on FK columns for all engines

Quick Reference

# Generate migration from entity changes
vendor/bin/doctrine-migrations diff

# Run pending migrations
vendor/bin/doctrine-migrations migrate

# Validate mapping
vendor/bin/doctrine orm:validate-schema

# Generate entity stubs (if using generator)
vendor/bin/doctrine orm:generate-entities src/

Related

  • Skill: symfony-patterns — Symfony integration (DoctrineBundle, autowiring repositories)
  • Skill: doctrine-odm-patterns — MongoDB document mapping (complementary skill)
  • Skill: php-static-analysis — PHPStan + phpstan-doctrine extension for type-safe queries
  • Agent: php-database-reviewer — schema and query review

Keep looking

Skills are one crate of 627,801. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.