Symfony

Doctrine ORM Basics

Entities, annotations, EntityManager, repositories, DQL, QueryBuilder, relationships

25 interview questionsยท
Junior
1

What is Doctrine ORM in the context of Symfony?

Answer

Doctrine ORM is an Object-Relational Mapper that allows manipulating database data through PHP objects. It abstracts SQL queries by providing an object layer, making code more maintainable and portable across different database management systems. It's the default recommended ORM with Symfony.

2

Which PHP 8 attribute should be used to declare a class as a Doctrine entity?

Answer

The #[ORM\Entity] attribute is used to indicate to Doctrine that a PHP class is an entity mapped to a database table. This attribute replaces comment-based annotations and is part of the Doctrine\ORM\Mapping namespace. It can be combined with repositoryClass to specify a custom repository.

3

How to define an auto-incremented column as a primary key in a Doctrine entity?

Answer

To define an auto-incremented primary key, two attributes must be combined: #[ORM\Id] to mark the property as identifier, and #[ORM\GeneratedValue] to indicate the value will be automatically generated by the database. The default strategy is AUTO, which selects the appropriate method based on the DBMS.

4

What is the difference between persist() and flush() in EntityManager?

5

Which attribute should be used to map a string property to a VARCHAR column in Doctrine?

+22 interview questions

Master Symfony for your next interview

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

Start for free