Skip to content

Commit a93d030

Browse files
authored
Merge pull request #2085 from cct-marketing/also-load-patch-2
Cast also-load xml attribute to string
2 parents 083c3fe + d8dff50 commit a93d030

7 files changed

Lines changed: 60 additions & 10 deletions

File tree

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
"Doctrine\\ODM\\MongoDB\\Benchmark\\": "benchmark",
4242
"Doctrine\\ODM\\MongoDB\\Tests\\": "tests/Doctrine/ODM/MongoDB/Tests",
4343
"Documents\\": "tests/Documents",
44-
"Stubs\\": "tests/Stubs"
44+
"Stubs\\": "tests/Stubs",
45+
"TestDocuments\\" :"tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/fixtures"
4546
}
4647
},
4748
"extra": {

doctrine-mongo-mapping.xsd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
<xs:attribute name="lock" type="xs:boolean" />
9999
<xs:attribute name="not-saved" type="xs:boolean" />
100100
<xs:attribute name="nullable" type="xs:boolean" />
101-
<xs:attribute name="also-load" type="xs:NMTOKEN" />
101+
<xs:attribute name="also-load" type="xs:string" />
102102
<!-- index options -->
103103
<xs:attribute name="background" type="xs:boolean" />
104104
<xs:attribute name="drop-dups" type="xs:boolean" />

lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public function loadMetadataForClass($className, ClassMetadata $class)
228228
}
229229

230230
if (isset($attributes['also-load'])) {
231-
$mapping['alsoLoadFields'] = explode(',', $attributes['also-load']);
231+
$mapping['alsoLoadFields'] = explode(',', (string) $attributes['also-load']);
232232
} elseif (isset($attributes['version'])) {
233233
$mapping['version'] = ('true' === (string) $attributes['version']);
234234
} elseif (isset($attributes['lock'])) {

tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/AbstractDriverTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
use TestDocuments\PrimedCollectionDocument;
77
use PHPUnit\Framework\TestCase;
88

9-
require_once 'fixtures/InvalidPartialFilterDocument.php';
10-
require_once 'fixtures/PartialFilterDocument.php';
11-
require_once 'fixtures/PrimedCollectionDocument.php';
12-
require_once 'fixtures/User.php';
13-
require_once 'fixtures/EmbeddedDocument.php';
14-
require_once 'fixtures/QueryResultDocument.php';
15-
169
abstract class AbstractDriverTest extends TestCase
1710
{
1811
protected $driver;

tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/XmlDriverTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
66
use Doctrine\ODM\MongoDB\Mapping\Driver\XmlDriver;
7+
use TestDocuments\AlsoLoadDocument;
78
use TestDocuments\UserCustomIdGenerator;
89
use TestDocuments\UserCustomIdGeneratorWithIdField;
910

@@ -87,6 +88,29 @@ public function testInvalidPartialFilterExpressions()
8788
],
8889
], $classMetadata->getIndexes());
8990
}
91+
92+
public function testAlsoLoadFieldMapping()
93+
{
94+
$classMetadata = new ClassMetadata(AlsoLoadDocument::class);
95+
$this->driver->loadMetadataForClass(AlsoLoadDocument::class, $classMetadata);
96+
97+
$this->assertEquals(array(
98+
'fieldName' => 'createdAt',
99+
'name' => 'createdAt',
100+
'type' => 'date',
101+
'isCascadeDetach' => false,
102+
'isCascadeMerge' => false,
103+
'isCascadePersist' => false,
104+
'isCascadeRefresh' => false,
105+
'isCascadeRemove' => false,
106+
'isInverseSide' => false,
107+
'isOwningSide' => true,
108+
'nullable' => false,
109+
'strategy' => ClassMetadata::STORAGE_STRATEGY_SET,
110+
'also-load' => 'createdOn,creation_date',
111+
'alsoLoadFields' => array('createdOn', 'creation_date'),
112+
), $classMetadata->fieldMappings['createdAt']);
113+
}
90114
}
91115

92116
namespace TestDocuments;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace TestDocuments;
4+
5+
class AlsoLoadDocument
6+
{
7+
protected $id;
8+
9+
protected $createdAt;
10+
11+
public function __construct()
12+
{
13+
$this->createdAt = new \DateTime();
14+
}
15+
16+
public function getId()
17+
{
18+
return $this->id;
19+
}
20+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
6+
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">
7+
8+
<document name="TestDocuments\AlsoLoadDocument" db="documents" collection="users">
9+
<field name="id" id="true" />
10+
<field name="createdAt" type="date" also-load="createdOn,creation_date"/>
11+
</document>
12+
</doctrine-mongo-mapping>

0 commit comments

Comments
 (0)