PHP › Symfony Framework Essentials
How does Doctrine ORM integrate with Symfony to let you work with database records as PHP objects, and what role do entities play in this?
IntermediateAnswer
Doctrine is the ORM most commonly used together with Symfony, and it lets you represent each database table as a corresponding PHP class, called an entity, with each property on that class mapped to a specific column, so that reading, creating, updating, or deleting a database record can be done by working with a familiar PHP object rather than writing raw SQL directly, and Doctrine also manages the underlying database schema itself through a system of migrations generated based on changes made to your entity classes.
#[ORM\Entity]
class Product
{
#[ORM\Id, ORM\GeneratedValue, ORM\Column]
private int $id;
#[ORM\Column(length: 255)]
private string $name;
}Real-world example A Symfony e commerce application defines a Product entity representing its products database table, letting developers work with familiar Product objects throughout the codebase instead of manually writing raw SQL queries for every single database interaction.