@@ -11,22 +11,18 @@ Mapping Drivers
11
11
Doctrine provides several different ways for specifying object
12
12
document mapping metadata:
13
13
14
- - Attributes
15
- - XML
14
+ - ` Attributes < annotations-reference >`_
15
+ - ` XML < xml-mapping >`_
16
16
- Raw PHP Code
17
17
18
18
.. note ::
19
19
20
- If you're wondering which mapping driver gives the best
21
- performance, the answer is: None. Once the metadata of a class has
22
- been read from the source (attributes or xml) it is stored
23
- in an instance of the
24
- ``Doctrine\ODM\MongoDB\Mapping\ClassMetadata `` class and these
25
- instances are stored in the metadata cache. Therefore at the end of
26
- the day all drivers perform equally well. If you're not using a
27
- metadata cache (not recommended!) then the XML driver might have a
28
- slight edge in performance due to the powerful native XML support
29
- in PHP.
20
+ If you're wondering which mapping driver gives the best performance, the
21
+ answer is: None. Once the metadata of a class has been read from the source
22
+ (Attributes or XML) it is stored in an instance of the
23
+ ``Doctrine\ODM\MongoDB\Mapping\ClassMetadata `` class and these instances are
24
+ stored in the metadata cache. Therefore all drivers perform equally well at
25
+ runtime.
30
26
31
27
Introduction to Attributes
32
28
--------------------------
@@ -61,6 +57,8 @@ to be designated as a document. This can be done through the
61
57
62
58
namespace Documents;
63
59
60
+ use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
61
+
64
62
#[Document]
65
63
class User
66
64
{
@@ -90,6 +88,8 @@ option as follows:
90
88
91
89
namespace Documents;
92
90
91
+ use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
92
+
93
93
#[Document(db: 'my_db', collection: 'users')]
94
94
class User
95
95
{
@@ -243,11 +243,14 @@ Here is an example:
243
243
244
244
namespace Documents;
245
245
246
+ use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
247
+ use Doctrine\ODM\MongoDB\Mapping\Annotations\Id;
248
+
246
249
#[Document]
247
250
class User
248
251
{
249
252
#[Id]
250
- private string $id;
253
+ public string $id;
251
254
}
252
255
253
256
.. code-block :: xml
@@ -280,16 +283,16 @@ Here is an example how to manually set a string identifier for your documents:
280
283
281
284
<?php
282
285
286
+ namespace Documents;
287
+
288
+ use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
289
+ use Doctrine\ODM\MongoDB\Mapping\Annotations\Id;
290
+
283
291
#[Document]
284
292
class MyPersistentClass
285
293
{
286
294
#[Id(strategy: 'NONE', type: 'string')]
287
- private string $id;
288
-
289
- public function setId(string $id): void
290
- {
291
- $this->id = $id;
292
- }
295
+ public string $id;
293
296
294
297
//...
295
298
}
@@ -406,13 +409,16 @@ Example:
406
409
407
410
namespace Documents;
408
411
412
+ use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
413
+ use Doctrine\ODM\MongoDB\Mapping\Annotations\Field;
414
+
409
415
#[Document]
410
416
class User
411
417
{
412
418
// ...
413
419
414
420
#[Field(type: 'string')]
415
- private string $username;
421
+ public string $username;
416
422
}
417
423
418
424
.. code-block :: xml
@@ -445,7 +451,7 @@ as follows:
445
451
class User
446
452
{
447
453
#[Field(name: 'db_name')]
448
- private string $name;
454
+ public string $name;
449
455
}
450
456
451
457
.. code-block :: xml
0 commit comments