Skip to content

Commit 8952edc

Browse files
committed
Merge pull request #1119 from BraisGabin/patch-1
How to configure Doctrine using yaml
2 parents 95a948e + 14f01c5 commit 8952edc

File tree

2 files changed

+149
-9
lines changed

2 files changed

+149
-9
lines changed

Resources/doc/groups.md

Lines changed: 103 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ Or if you prefer XML:
4848
The simplest way to create a Group class is to extend the mapped superclass
4949
provided by the bundle.
5050

51-
**a) ORM Group class implementation**
51+
#### a) ORM Group class implementation
5252

53+
##### Annotations
5354
``` php
5455
// src/MyProject/MyBundle/Entity/Group.php
5556
<?php
@@ -76,7 +77,47 @@ class Group extends BaseGroup
7677

7778
**Note:** `Group` is a reserved keyword in SQL so it cannot be used as the table name.
7879

79-
**b) MongoDB Group class implementation**
80+
##### yaml
81+
82+
83+
```php
84+
<?php
85+
// src/Acme/UserBundle/Entity/Group.php
86+
87+
namespace Acme\UserBundle\Entity;
88+
89+
use FOS\UserBundle\Entity\Group as BaseGroup;
90+
91+
/**
92+
* Group
93+
*/
94+
class Group extends BaseGroup
95+
{
96+
/**
97+
* @var integer
98+
*/
99+
protected $id;
100+
101+
public function __construct()
102+
{
103+
parent::__construct();
104+
// your own logic
105+
}
106+
}
107+
```
108+
```yaml
109+
# src/Acme/UserBundle/Resources/config/doctrine/Group.orm.yml
110+
Acme\UserBundle\Entity\Group:
111+
type: entity
112+
table: fos_group
113+
id:
114+
id:
115+
type: integer
116+
generator:
117+
strategy: AUTO
118+
```
119+
120+
#### b) MongoDB Group class implementation
80121
81122
``` php
82123
// src/MyProject/MyBundle/Document/Group.php
@@ -99,7 +140,7 @@ class Group extends BaseGroup
99140
}
100141
```
101142

102-
**c) CouchDB Group class implementation**
143+
#### c) CouchDB Group class implementation
103144

104145
``` php
105146
// src/MyProject/MyBundle/Document/Group.php
@@ -126,8 +167,9 @@ class Group extends BaseGroup
126167

127168
The next step is to map the relation in your `User` class.
128169

129-
**a) ORM User-Group mapping**
170+
#### a) ORM User-Group mapping
130171

172+
##### Annotations
131173
``` php
132174
// src/MyProject/MyBundle/Entity/User.php
133175
<?php
@@ -161,7 +203,62 @@ class User extends BaseUser
161203
}
162204
```
163205

164-
**b) MongoDB User-Group mapping**
206+
##### yaml
207+
```php
208+
<?php
209+
// src/Acme/UserBundle/Entity/User.php
210+
211+
namespace Acme\UserBundle\Entity;
212+
213+
use FOS\UserBundle\Entity\User as BaseUser;
214+
215+
/**
216+
* User
217+
*/
218+
class User extends BaseUser
219+
{
220+
/**
221+
* @var integer
222+
*/
223+
protected $id;
224+
225+
/**
226+
* @var \Doctrine\Common\Collections\Collection
227+
*/
228+
protected $groups;
229+
230+
public function __construct()
231+
{
232+
parent::__construct();
233+
$this->groups = new \Doctrine\Common\Collections\ArrayCollection();
234+
// your own logic
235+
}
236+
}
237+
```
238+
```yaml
239+
# src/Acme/UserBundle/Resources/config/doctrine/User.orm.yml
240+
Acme\UserBundle\Entity\User:
241+
type: entity
242+
table: fos_user
243+
id:
244+
id:
245+
type: integer
246+
generator:
247+
strategy: AUTO
248+
manyToMany:
249+
groups:
250+
targetEntity: Group
251+
joinTable:
252+
name: fos_user_group
253+
joinColumns:
254+
user_id:
255+
referencedColumnName: id
256+
inverseJoinColumns:
257+
group_id:
258+
referencedColumnName: id
259+
```
260+
261+
#### b) MongoDB User-Group mapping
165262
166263
``` php
167264
// src/MyProject/MyBundle/Document/User.php
@@ -187,7 +284,7 @@ class User extends BaseUser
187284
}
188285
```
189286

190-
**c) CouchDB User-Group mapping**
287+
#### c) CouchDB User-Group mapping
191288

192289
``` php
193290
// src/MyProject/MyBundle/Document/User.php

Resources/doc/index.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,14 @@ or CouchDB ODM).
116116
> to call parent::__construct(), as the base User class depends on
117117
> this to initialize some fields.
118118
119-
**a) Doctrine ORM User class**
119+
#### a) Doctrine ORM User class
120120

121121
If you're persisting your users via the Doctrine ORM, then your `User` class
122122
should live in the `Entity` namespace of your bundle and look like this to
123123
start:
124124

125+
##### Annotations
126+
125127
``` php
126128
<?php
127129
// src/Acme/UserBundle/Entity/User.php
@@ -156,7 +158,48 @@ class User extends BaseUser
156158

157159
> `User` is a reserved keyword in SQL so you cannot use it as table name.
158160
159-
**b) MongoDB User class**
161+
##### yaml
162+
163+
If you use yml to configure Doctrine you must add two files. The Entity and the orm.yml:
164+
165+
```php
166+
<?php
167+
// src/Acme/UserBundle/Entity/User.php
168+
169+
namespace Acme\UserBundle\Entity;
170+
171+
use FOS\UserBundle\Entity\User as BaseUser;
172+
173+
/**
174+
* User
175+
*/
176+
class User extends BaseUser
177+
{
178+
/**
179+
* @var integer
180+
*/
181+
protected $id;
182+
183+
public function __construct()
184+
{
185+
parent::__construct();
186+
// your own logic
187+
}
188+
}
189+
```
190+
```yaml
191+
# src/Acme/UserBundle/Resources/config/doctrine/User.orm.yml
192+
Acme\UserBundle\Entity\User:
193+
type: entity
194+
table: fos_user
195+
id:
196+
id:
197+
type: integer
198+
generator:
199+
strategy: AUTO
200+
```
201+
202+
#### b) MongoDB User class
160203
161204
If you're persisting your users via the Doctrine MongoDB ODM, then your `User`
162205
class should live in the `Document` namespace of your bundle and look like
@@ -189,7 +232,7 @@ class User extends BaseUser
189232
}
190233
```
191234

192-
**c) CouchDB User class**
235+
#### c) CouchDB User class
193236

194237
If you're persisting your users via the Doctrine CouchDB ODM, then your `User`
195238
class should live in the `CouchDocument` namespace of your bundle and look like

0 commit comments

Comments
 (0)