
Doctrine Advanced
Migrations, lifecycle callbacks, events, inheritance, custom types, performance optimization
1Which command generates a new Doctrine migration in Symfony?
Which command generates a new Doctrine migration in Symfony?
Answer
The doctrine:migrations:diff command compares the current database schema with entity metadata and automatically generates a migration containing the differences. This is the recommended method for creating migrations as it avoids manual errors and ensures consistency between code and database.
2Which lifecycle callback is triggered before an entity is inserted into the database?
Which lifecycle callback is triggered before an entity is inserted into the database?
Answer
The PrePersist callback is executed before a new entity is persisted to the database. This is the ideal place to initialize default values like creation timestamps or generate unique identifiers before insertion.
3How to enable lifecycle callbacks on a Doctrine entity?
How to enable lifecycle callbacks on a Doctrine entity?
Answer
The HasLifecycleCallbacks attribute must be added to the entity class to enable callbacks. Without this attribute, methods annotated with PrePersist, PostUpdate and other callbacks will never be executed by Doctrine.
Which command executes all pending migrations in Doctrine?
Which Doctrine callback to use for automatically updating an 'updatedAt' field on each modification?
+21 interview questions
Other Symfony interview topics
Modern PHP (8.1+)
Symfony Basics
Routing & Controllers
Twig & Templates
Doctrine ORM Basics
Symfony Forms
Data Validation
Dependency Injection & Services
Security & Authentication
API Platform
Serializer Component
Events & Event Subscribers
Console & Commands
Messenger Component
HTTP Client
Cache & Performance
Workflow Component
Testing Symfony
Mailer Component
Translations & i18n
EasyAdmin Bundle
Symfony Architecture
Performance & Optimization
Security Advanced
Custom Bundles
Microservices with Symfony
Real-time & WebSockets
Deployment & DevOps
Master Symfony for your next interview
Access all questions, flashcards, technical tests, code review exercises and interview simulators.
Start for free