Skip to content

Instantly share code, notes, and snippets.

@mnapoli
Last active January 12, 2023 00:08
Show Gist options
  • Save mnapoli/3839501 to your computer and use it in GitHub Desktop.
Save mnapoli/3839501 to your computer and use it in GitHub Desktop.
Doctrine YAML configuration reference
# Inspired from http://blog.hio.fr/2011/09/17/doctrine2-yaml-mapping-example.html
MyEntity:
type: entity
repositoryClass: MyRepositoryClass
table: my_entity
namedQueries:
all: "SELECT u FROM __CLASS__ u"
# Class-Table-Inheritance
inheritanceType: joined
discriminatorColumn:
name: type
type: string
discriminatorMap:
class1: MyClass1
class2: MyClass2
id:
id:
type: integer
generator:
strategy: AUTO
sequenceGenerator:
sequenceName: tablename_seq
allocationSize: 100
initialValue: 1
fields:
name:
type: string
length: 50
nullable: true
unique: true
email:
type: string
column: user_email
columnDefinition: CHAR(32) NOT NULL
oneToOne:
address:
targetEntity: Address
inversedBy: user
joinColumn:
name: address_id
referencedColumnName: id
onDelete: CASCADE
onUpdate: CASCADE
cascade: [ remove ]
oneToMany:
phonenumbers:
targetEntity: PhoneNumber
orphanRemoval: true
mappedBy: user
orderBy:
number: ASC
cascade: [ persist ]
fetch: EAGER
# ManyToMany unidirectionnal
manyToMany:
groups:
targetEntity: Group
joinTable:
name: users_groups
joinColumns:
user_id:
referencedColumnName: id
inverseJoinColumns:
group_id:
referencedColumnName: id
# ManyToMany bidirectionnal
manyToMany:
groups:
targetEntity: Group
inversedBy: users
joinTable:
name: users_groups
joinColumns:
user_id:
referencedColumnName: id
nullable: false
unique: false
inverseJoinColumns:
group_id:
referencedColumnName: id
columnDefinition: INT NULL
cascade:
- all
# Inverse side
Group:
type: entity
manyToMany:
users:
targetEntity: User
mappedBy: groups
manyToOne:
securityLevel:
targetEntity: SecurityLevel
inversedBy: users
joinColumn:
name: securitylevel_id
referencedColumnName: id
nullable: false
# Referencing an entity with a multiple columns primary key
manyToOne:
location:
targetEntity: Location
joinColumns:
- name: location_latitude
referencedColumnName: latitude
nullable: false
- name: location_longitude
referencedColumnName: longitude
nullable: false
lifecycleCallbacks:
prePersist: [ doStuffOnPrePersist, doOtherStuffOnPrePersistToo ]
postPersist: [ doStuffOnPostPersist ]
preUpdate: [ preUpdate ]
preRemove: [ preDelete ]
postLoad: [ postLoad ]
uniqueConstraints:
search_idx:
columns: [name, user_email]
indexes:
name_idx:
columns: name
0:
columns: user_email
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment