Show Menu
Cheatography

Doctrine ORM Annotations Cheat Sheet by

Doctrine 2 ORM Annotations Reference

@Id

For entities that have multiple identifier columns each column has to be marked with @Id.

@Index

name str
columns []
Columns
options []
where

@Column

type str
name str
length int
options []
default, unsigned, fixed ...
unique bool
nullable bool
column­Def­inition str
DQL definition
precision int
scale int
"precision" and "scale" are only for decimal columns.

@Colum­nResult

name str

@Cache

usage ch
see choices below
region str
READ_ONLY, READ_W­RIT­E,N­ONS­TRI­CT_­REA­D_WRITE

@Chang­eTr­ack­ing­Policy

/**
 * @Entity
 * @ChangeTrackingPolicy("DEFERRED_IMPLICIT")
 * @ChangeTrackingPolicy("DEFERRED_EXPLICIT")
 * @ChangeTrackingPolicy("NOTIFY")
 */
class User {}

@Entity

reposi­tor­yClass (string)
readOnly (boolean)

@Entit­yResult

entity­Class (string)
fields (array­|Fi­eld­Result)
discri­min­ato­rColumn (string)

@Field­Result

name (string)
column (string)

@Gener­ate­dValue

strategy (choice : AUTO, SEQUENCE, TABLE, IDENTITY, UUID, CUSTOM or NONE)
 

@OneToOne

target­Entity (string)
cascade (array­|ca­scades actions)
fetch (choice: LAZY, EAGER)
orphan­Removal (boolean)
inversedBy (string)

@ManyToOne

target­Entity (string)
cascade (array­|ca­scades actions)
fetch (choice: LAZY, EAGER)
inversedBy (string)

@OneToMany

target­Entity (string)
cascade (array­|ca­scades actions)
orphan­Removal (boolean)
mappedBy (string)
fetch (choice: LAZY, EXTRA_­LAZY, EAGER)
indexBy (string)

@ManyT­oMany

target­Entity (string)
mappedBy (string)
inversedBy (string)
cascade (array­|ca­scades actions)
fetch (choice: LAZY, EXTRA_­LAZY, EAGER)
indexBy (string)

@OrderBy

/**
 * @ManyToMany(targetEntity="Group")
 * @OrderBy({"name" = "ASC"})
 */
private $groups;
See @ManyT­oMany or @OneTo­Many.

@JoinC­olumn

name (string)
refere­nce­dCo­lum­nName (string)
unique (boolean)
nullable (bool)
onDelete (array­|ca­scades actions)
column­Def­inition (string : DQL definition)
See @ManyToOne and @OneToOne.

@JoinTable

name (string)
joinCo­lumns (array­|@J­oin­Column)
invers­eJo­inC­olumns (array­|@J­oin­Column)

@JoinC­olumns

Array of @JoinC­olumn.
 

@Seque­nce­Gen­erator

sequen­ceName (string)
alloca­tio­nSize (integer)
initia­lValue (integer)

@SqlRe­sul­tSe­tMa­pping

name (string)
entities (array­|@E­nti­tyR­esult)
columns (array­|@C­olu­mnR­esult)

@Table

name (string)
indexes (array­|@I­ndex)
unique­Con­str­aints (array­|@U­niq­ueC­ons­traint)
schema (string)

@Uniqu­eCo­nst­raint

name (string)
columns (array­|co­lumn)
options (array|: where)

@Mappe­dSu­per­class

reposi­tor­yClass (string)

@Named­Nat­ive­Query

name (string)
query (string)
result­Class (string)
result­Set­Mapping (strin­g|S­qlR­esu­ltS­etM­apping)

@Version

It only works on integer or datetime @Columns.

@Inher­ita­nceType

/**
 * @Entity
 * @InheritanceType("SINGLE_TABLE")
...
/**
 * @Entity
 * @InheritanceType("JOINED")
See @Discr­imi­nat­orMap and @Discr­imi­nat­orC­olumn.

@Discr­imi­nat­orMap

/**
 * @Entity
 * @InheritanceType("JOINED")
 * @DiscriminatorColumn(name="discr", type="string")
 * @DiscriminatorMap({"person" = "Person", "employee" = "Employee"})
 */
class Person {}

@Discr­imi­nat­orC­olumn

name (string)
type (string)
length (int)

@HasLi­fec­ycl­eCa­llbacks

See @PostLoad, @PrePe­rsist, @PostP­ersist, @PreRe­move, @PostR­emove, @PreUpdate or @PostU­pdate.
           
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          RedBeanPHP Class Reference Cheat Sheet
          Projeto Zend Framework 2 + Doctrine 2 Cheat Sheet
          Symfony 5 Cheat Sheet