Last active
August 29, 2015 14:27
-
-
Save alcaeus/2c805da6bdc17086c700 to your computer and use it in GitHub Desktop.
ID mapping with generator overriding custom_id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace My\Custom; | |
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; | |
class Document { | |
/** | |
* This works | |
* | |
* @ODM\Id( | |
* strategy="custom", | |
* options={ | |
* "class"="My\Custom\MongoIdGenerator", | |
* "type"="id" | |
* } | |
* ) | |
*/ | |
protected $id; | |
/** | |
* This doesn't work | |
* | |
* @ODM\Id( | |
* type="My\Custom\IdType", | |
* strategy="custom", | |
* options={ | |
* "class"="My\Custom\MongoIdGenerator" | |
* } | |
* ) | |
*/ | |
protected $id; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping | |
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd"> | |
<document name="My\Custom\Document" db="documents" collection="documents"> | |
<!-- Works --> | |
<field name="id" id="true" strategy="custom"> | |
<id-generator-option name="class" value="My\Custom\MongoIdGenerator"/> | |
<id-generator-option name="type" value="id"/> | |
</field> | |
<!-- Doesn't work --> | |
<field name="id" id="true" strategy="custom"> | |
<id-generator-option name="class" value="My\Custom\MongoIdGenerator"/> | |
</field> | |
</document> | |
</doctrine-mongo-mapping> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
My\Custom\Document: | |
db: documents | |
collection: documents | |
fields: | |
# Works | |
id: | |
fieldName: id | |
id: true | |
strategy: custom | |
generatorOptions: | |
class: My\Custom\MongoIdGenerator | |
type: id | |
# Doesn't work | |
id: | |
fieldName: id | |
id: true | |
strategy: custom | |
generatorOptions: | |
class: My\Custom\MongoIdGenerator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment