Skip to content

Commit 5632b82

Browse files
committed
Merge pull request #1204
2 parents 24e2356 + 1bb6697 commit 5632b82

1 file changed

Lines changed: 52 additions & 2 deletions

File tree

docs/en/reference/basic-mapping.rst

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,15 +300,14 @@ Here is how you can configure the strategy for the different configuration forma
300300
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
301301
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">
302302
303-
<document name="MyPersistentClass" customId="true">
303+
<document name="MyPersistentClass">
304304
<field name="id" id="true" strategy="NONE" />
305305
</document>
306306
</doctrine-mongo-mapping>
307307
308308
.. code-block:: yaml
309309
310310
MyPersistentClass:
311-
customId: true
312311
fields:
313312
id:
314313
id: true
@@ -337,6 +336,57 @@ Now you can retrieve the document later:
337336
338337
$document = $dm->find('MyPersistentClass', 'my_unique_identifier');
339338
339+
You can define your own ID generator by extending the
340+
``Doctrine\ODM\MongoDB\Id\AbstractIdGenerator`` class and specifying the class
341+
as an option for the ``CUSTOM`` strategy:
342+
343+
.. configuration-block::
344+
345+
.. code-block:: php
346+
347+
<?php
348+
349+
/** Document */
350+
class MyPersistentClass
351+
{
352+
/** @Id(strategy="CUSTOM", type="string", options={"class"="Vendor\Specific\Generator"}) */
353+
private $id;
354+
355+
public function setId($id)
356+
{
357+
$this->id = $id;
358+
}
359+
360+
//...
361+
}
362+
363+
.. code-block:: xml
364+
365+
<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping"
366+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
367+
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
368+
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">
369+
370+
<document name="MyPersistentClass">
371+
<field name="id" id="true" strategy="CUSTOM" type="string">
372+
<id-generator-option name="class" value="Vendor\Specific\Generator" />
373+
</field>
374+
</document>
375+
</doctrine-mongo-mapping>
376+
377+
.. code-block:: yaml
378+
379+
MyPersistentClass:
380+
fields:
381+
id:
382+
id: true
383+
strategy: CUSTOM
384+
type: string
385+
options:
386+
class: Vendor\Specific\Generator
387+
388+
389+
340390
Fields
341391
~~~~~~
342392

0 commit comments

Comments
 (0)