Skip to content

Commit 3561c03

Browse files
committed
Review basic mapping
1 parent 369abc5 commit 3561c03

File tree

3 files changed

+31
-32
lines changed

3 files changed

+31
-32
lines changed

docs/en/reference/annotations-reference.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Change the metadata driver configuration to use the ``AttributeDriver``:
2020
- $config->setMetadataDriverImpl(AnnotationsDriver::create(__DIR__ . '/Documents'));
2121
+ $config->setMetadataDriverImpl(AttributeDriver::create(__DIR__ . '/Documents'));
2222
23-
Replace the `@ORM\Document` annotations with the `#[ORM\Document]` attribute.
23+
Replace the ``@ORM\Document`` annotations with the ``#[ORM\Document]`` attribute.
2424

2525
.. code-block:: diff
2626

docs/en/reference/basic-mapping.rst

+27-21
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,18 @@ Mapping Drivers
1111
Doctrine provides several different ways for specifying object
1212
document mapping metadata:
1313

14-
- Attributes
15-
- XML
14+
- `Attributes <annotations-reference>`_
15+
- `XML <xml-mapping>`_
1616
- Raw PHP Code
1717

1818
.. note::
1919

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.
3026

3127
Introduction to Attributes
3228
--------------------------
@@ -61,6 +57,8 @@ to be designated as a document. This can be done through the
6157
6258
namespace Documents;
6359
60+
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
61+
6462
#[Document]
6563
class User
6664
{
@@ -90,6 +88,8 @@ option as follows:
9088
9189
namespace Documents;
9290
91+
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
92+
9393
#[Document(db: 'my_db', collection: 'users')]
9494
class User
9595
{
@@ -243,11 +243,14 @@ Here is an example:
243243
244244
namespace Documents;
245245
246+
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
247+
use Doctrine\ODM\MongoDB\Mapping\Annotations\Id;
248+
246249
#[Document]
247250
class User
248251
{
249252
#[Id]
250-
private string $id;
253+
public string $id;
251254
}
252255
253256
.. code-block:: xml
@@ -280,16 +283,16 @@ Here is an example how to manually set a string identifier for your documents:
280283
281284
<?php
282285
286+
namespace Documents;
287+
288+
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
289+
use Doctrine\ODM\MongoDB\Mapping\Annotations\Id;
290+
283291
#[Document]
284292
class MyPersistentClass
285293
{
286294
#[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;
293296
294297
//...
295298
}
@@ -406,13 +409,16 @@ Example:
406409
407410
namespace Documents;
408411
412+
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
413+
use Doctrine\ODM\MongoDB\Mapping\Annotations\Field;
414+
409415
#[Document]
410416
class User
411417
{
412418
// ...
413419
414420
#[Field(type: 'string')]
415-
private string $username;
421+
public string $username;
416422
}
417423
418424
.. code-block:: xml
@@ -445,7 +451,7 @@ as follows:
445451
class User
446452
{
447453
#[Field(name: 'db_name')]
448-
private string $name;
454+
public string $name;
449455
}
450456
451457
.. code-block:: xml

docs/en/reference/xml-mapping.rst

+3-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ form of XML documents.
77
The XML driver is backed by an XML Schema document that describes
88
the structure of a mapping document. The most recent version of the
99
XML Schema document is available online at
10-
`http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd <http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd>`_.
10+
`https://www.doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd <https://www.doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd>`_.
1111
The most convenient way to work with XML mapping files is to use an
1212
IDE/editor that can provide code-completion based on such an XML
1313
Schema document. The following is an outline of a XML mapping
@@ -19,19 +19,12 @@ trunk.
1919
<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping"
2020
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2121
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
22-
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">
22+
http://www.doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">
2323
2424
...
2525
2626
</doctrine-mongo-mapping>
2727
28-
.. note::
29-
30-
If you do not want to use latest XML Schema document please use link like
31-
`http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping-1.0.0-BETA12.xsd <http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping-1.0.0-BETA12.xsd>`_.
32-
You can change ``1.0.0-BETA12`` part of the URL to
33-
`any other ODM version <https://github.com/doctrine/mongodb-odm/releases>`_.
34-
3528
The XML mapping document of a class is loaded on-demand the first
3629
time it is requested and subsequently stored in the metadata cache.
3730
In order to work, this requires certain conventions:
@@ -106,7 +99,7 @@ of several common elements:
10699
<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping"
107100
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
108101
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
109-
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">
102+
http://www.doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">
110103
111104
<document name="Documents\User" db="documents" collection="users">
112105
<id />

0 commit comments

Comments
 (0)