Symfony

Doctrine Advanced

Migrations, lifecycle callbacks, events, inheritance, custom types, performance optimization

24 interview questionsยท
Mid-Level
1

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.

2

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.

3

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.

4

Which command executes all pending migrations in Doctrine?

5

Which Doctrine callback to use for automatically updating an 'updatedAt' field on each modification?

+21 interview questions

Master Symfony for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free