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 defini­tion
precision int
scale int
pr­eci­sio­n" and "­sc­ale­" 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_W­RITE

@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

enti­tyC­lass (string)
fields (array­|Fi­eld­Result)
discri­min­ato­rColumn (string)

@Field­Result

name (string)
column (string)

@Gener­ate­dValue

stra­tegy (choice : AUTO, SEQUENCE, TABLE, IDENTITY, UUID, CUSTOM or NONE)
 

@OneToOne

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

@ManyToOne

targ­etE­ntity (string)
cascade (array­|ca­scades actions)
fetch (choice: LAZY, EAGER)
inversedBy (string)

@OneToMany

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

@ManyT­oMany

targ­etE­ntity (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)
refe­ren­ced­Col­umn­Name (string)
unique (boolean)
nullable (bool)
onDelete (array­|ca­scades actions)
column­Def­inition (string : DQL defini­tion)
See @ManyToOne and @OneTo­One.

@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

sequ­enc­eName (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)
colu­mns (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.
           

Help Us Go Positive!

We offset our carbon usage with Ecologi. Click the link below to help us!

We offset our carbon footprint via Ecologi
 

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

          PHP Cheat Sheet
          RedBeanPHP Class Reference Cheat Sheet
          Projeto Zend Framework 2 + Doctrine 2 Cheat Sheet