Skip to content

Instantly share code, notes, and snippets.

@Falc
Forked from mnapoli/reference.yml
Last active August 29, 2015 14:06
Show Gist options
  • Save Falc/82a580b41b56cb2e4a96 to your computer and use it in GitHub Desktop.
Save Falc/82a580b41b56cb2e4a96 to your computer and use it in GitHub Desktop.
# 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 ]
# 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