Archives du mot-clef doctrine2

doctrine2 yaml mapping example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Doctrine\Tests\ORM\Mapping\User:
  type: entity
  table: cms_users
  namedQueries:
    all: SELECT u FROM __CLASS__ u
  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:
    groups:
      targetEntity: Group
      joinTable:
        name: cms_users_groups
        joinColumns:
          user_id:
            referencedColumnName: id
            nullable: false
            unique: false
        inverseJoinColumns:
          group_id:
            referencedColumnName: id
            columnDefinition: INT NULL
      cascade:
        - all
  lifecycleCallbacks:
    prePersist: [ doStuffOnPrePersist, doOtherStuffOnPrePersistToo ]
    postPersist: [ doStuffOnPostPersist ]
  uniqueConstraints:
    search_idx:
      columns: name,user_email
  indexes:
    name_idx:
      columns: name
    0:
      columns: user_email

Doctrine Field Types Reference

Strings

string (used for shorter strings)
text (used for larger strings)
Numbers
integer
smallint
bigint
decimal
float

Dates and Times (use a DateTime object for these fields in PHP)

date
time
datetime

Other Types

boolean
object (serialized and stored in a CLOB field)
array (serialized and stored in a CLOB field)