Skip to content

Commit

Permalink
Merge pull request #2097 from alcaeus/gh-2096
Browse files Browse the repository at this point in the history
Fix wrong handling of custom identifier names
  • Loading branch information
alcaeus committed Nov 6, 2019
2 parents a93d030 + d424958 commit 182a04b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ public function loadMetadataForClass($className, ClassMetadata $class)
$mapping[$key] = (string) $value;
}

if (isset($attributes['field-name'])) {
$mapping['fieldName'] = (string) $attributes['field-name'];
}

if (isset($mapping['strategy'])) {
$mapping['options'] = [];
if (isset($field->{'generator-option'})) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function testDocumentLevelWriteConcern($class)
public function testFieldMappings($class)
{
$this->assertCount(14, $class->fieldMappings);
$this->assertTrue(isset($class->fieldMappings['id']));
$this->assertTrue(isset($class->fieldMappings['identifier']));
$this->assertTrue(isset($class->fieldMappings['version']));
$this->assertTrue(isset($class->fieldMappings['lock']));
$this->assertTrue(isset($class->fieldMappings['name']));
Expand Down Expand Up @@ -146,7 +146,7 @@ public function testStringFieldMappings($class)
*/
public function testIdentifier($class)
{
$this->assertEquals('id', $class->identifier);
$this->assertEquals('identifier', $class->identifier);

return $class;
}
Expand Down Expand Up @@ -402,7 +402,7 @@ class AbstractMappingDriverUser
/**
* @ODM\Id
*/
public $id;
public $identifier;

/**
* @ODM\Version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</tag-set>
<tag-set />
</read-preference>
<field fieldName="id" id="true" />
<id field-name="identifier" />
<field fieldName="version" version="true" type="int" />
<field fieldName="lock" lock="true" type="int" />
<field fieldName="name" name="username" type="string" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Doctrine\ODM\MongoDB\Tests\Mapping\AbstractMappingDriverUser:
fields:
id:
type: id
fieldName: identifier
id: true
version:
type: int
Expand Down

0 comments on commit 182a04b

Please sign in to comment.