doctrine/mongodb-odm — Issue #227: Can a discriminator field ever trigger a duplicate field mapping exception?
Author: jmikola
Created: 2012-01-09 05:10:57+00:00
State: open

We have this method in `ClassMetadataInfo`:

```
public function setDiscriminatorField($discriminatorField)
{
if ( ! isset($discriminatorField['name']) && isset($discriminatorField['fieldName'])) {
$discriminatorField['name'] = $discriminatorField['fieldName'];
}
if (isset($this->fieldMappings[$discriminatorField['name']])) {
throw MongoDBException::duplicateFieldMapping($this->name, $discriminatorField['name']);
}
$this->discriminatorField = $discriminatorField;
}
```

Based on how annotations are loaded, the discriminator annotations are processed at the class doc-block level and presumably before any field-level annotations. Therefore, I don't think any field mappings would exist at the time this method is called.

Perhaps it's more relevant for metadata defined in PHP, XML, and YAML?

The example in the [annotations reference](http://www.doctrine-project.org/docs/mongodb_odm/1.0/en/reference/annotations-reference.html#discriminatormap) actually has a field mapping declared on the property corresponding to the discriminator field. That's the very thing I expect would trigger this exception, if the same example was ported to XML or YAML.