Mapping with Doctrine annotations
Post
is a simple class with four properties. The setter for $id
isn't actually generated. Doctrine populates the $id
instance variable directly in the entity hydration phase. We will see later how we delegate the ID generation to the DBMS.
Doctrine annotations are imported from the \Doctrine\ORM\Mapping
namespace with use
statements. They are used in DocBlocks to add mapping information to the class and its properties. DocBlocks are just a special kind of comment starting with /**
.
Knowing about the @Entity annotation
The @Entity
annotation is used in the class-level DocBlock to specify that this class is an entity class.
The most important attribute of this annotation is repositoryClass
. It allows specifying a custom entity repository class. We will learn about entity repositories, including how to make a custom one, in Chapter 4, Building Queries.
Understanding the @Table, @Index, and @UniqueConstraint annotations
The @Table
annotation is optional. It can be...