Doctrine ORM good practices and tricks
summary
Start from domain entities and behavior not tables: design valid, immutable objects with named constructors, DTOs for multi-step forms, and no setters, immutable valid entities. Avoid lifecycle callbacks for business logic, avoid eager/extra‑lazy and bidirectional associations, and prefer annotations for private packages, XML for public. Use use UUIDs instead of autoincrement (claim: generating 100 UUIDs/sec for 100 years still yields only ~50% collision risk), prefer append‑only events for history, inject repositories (don’t extend Doctrine base), and try Doctrine 2.5’s second‑level cache.
AI-written summary · about
chapters (18)
- 0:00Introduction and speaker background
- 3:11When to use ORM and its limitations
- 8:33Designing entities first
- 15:34Law of Demeter and entity coupling
- 20:41Entity validity and DTOs
- 24:55Avoiding framework dependencies
- 28:07Lifecycle callbacks and auto-increment issues
- 32:25Using UUIDs instead of auto-increment
- 36:44Immutable entities and event sourcing
- 39:58Soft deletes and domain concepts
- 43:39Mapping driver choice
- 45:08Lazy loading and bidirectional associations
- 47:38Custom repositories and query functions
- 51:36Transaction management and entity manager
- 53:44Normalization and database design
- 54:44Performance profiling and optimization
- 55:48Recap and key takeaways
- 57:15Q&A session
