Skip to content

Commit

Permalink
Review basic mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Jul 3, 2024
1 parent 369abc5 commit 4e5a6b2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion docs/en/reference/annotations-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Change the metadata driver configuration to use the ``AttributeDriver``:
- $config->setMetadataDriverImpl(AnnotationsDriver::create(__DIR__ . '/Documents'));
+ $config->setMetadataDriverImpl(AttributeDriver::create(__DIR__ . '/Documents'));
Replace the `@ORM\Document` annotations with the `#[ORM\Document]` attribute.
Replace the ``@ORM\Document`` annotations with the ``#[ORM\Document]`` attribute.

.. code-block:: diff
Expand Down
48 changes: 27 additions & 21 deletions docs/en/reference/basic-mapping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,18 @@ Mapping Drivers
Doctrine provides several different ways for specifying object
document mapping metadata:

- Attributes
- XML
- `Attributes <annotations-reference>`_
- `XML <xml-mapping>`_
- Raw PHP Code

.. note::

If you're wondering which mapping driver gives the best
performance, the answer is: None. Once the metadata of a class has
been read from the source (attributes or xml) it is stored
in an instance of the
``Doctrine\ODM\MongoDB\Mapping\ClassMetadata`` class and these
instances are stored in the metadata cache. Therefore at the end of
the day all drivers perform equally well. If you're not using a
metadata cache (not recommended!) then the XML driver might have a
slight edge in performance due to the powerful native XML support
in PHP.
If you're wondering which mapping driver gives the best performance, the
answer is: None. Once the metadata of a class has been read from the source
(Attributes or XML) it is stored in an instance of the
``Doctrine\ODM\MongoDB\Mapping\ClassMetadata`` class and these instances are
stored in the metadata cache. Therefore all drivers perform equally well at
runtime.

Introduction to Attributes
--------------------------
Expand Down Expand Up @@ -61,6 +57,8 @@ to be designated as a document. This can be done through the
namespace Documents;
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
#[Document]
class User
{
Expand Down Expand Up @@ -90,6 +88,8 @@ option as follows:
namespace Documents;
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
#[Document(db: 'my_db', collection: 'users')]
class User
{
Expand Down Expand Up @@ -243,11 +243,14 @@ Here is an example:
namespace Documents;
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations\Id;
#[Document]
class User
{
#[Id]
private string $id;
public string $id;
}
.. code-block:: xml
Expand Down Expand Up @@ -280,16 +283,16 @@ Here is an example how to manually set a string identifier for your documents:
<?php
namespace Documents;
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations\Id;
#[Document]
class MyPersistentClass
{
#[Id(strategy: 'NONE', type: 'string')]
private string $id;
public function setId(string $id): void
{
$this->id = $id;
}
public string $id;
//...
}
Expand Down Expand Up @@ -406,13 +409,16 @@ Example:
namespace Documents;
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations\Field;
#[Document]
class User
{
// ...
#[Field(type: 'string')]
private string $username;
public string $username;
}
.. code-block:: xml
Expand Down Expand Up @@ -445,7 +451,7 @@ as follows:
class User
{
#[Field(name: 'db_name')]
private string $name;
public string $name;
}
.. code-block:: xml
Expand Down
9 changes: 1 addition & 8 deletions docs/en/reference/xml-mapping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ form of XML documents.
The XML driver is backed by an XML Schema document that describes
the structure of a mapping document. The most recent version of the
XML Schema document is available online at
`http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd <http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd>`_.
`http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd <https://www.doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd>`_.
The most convenient way to work with XML mapping files is to use an
IDE/editor that can provide code-completion based on such an XML
Schema document. The following is an outline of a XML mapping
Expand All @@ -25,13 +25,6 @@ trunk.
</doctrine-mongo-mapping>
.. note::

If you do not want to use latest XML Schema document please use link like
`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>`_.
You can change ``1.0.0-BETA12`` part of the URL to
`any other ODM version <https://github.com/doctrine/mongodb-odm/releases>`_.

The XML mapping document of a class is loaded on-demand the first
time it is requested and subsequently stored in the metadata cache.
In order to work, this requires certain conventions:
Expand Down

0 comments on commit 4e5a6b2

Please sign in to comment.