Skip to content

Commit 14f01c5

Browse files
committed
Groups ORM with yaml
1 parent eb31694 commit 14f01c5

File tree

1 file changed

+103
-6
lines changed

1 file changed

+103
-6
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

0 commit comments

Comments
 (0)