Skip to content

Commit

Permalink
Merge pull request #2085 from cct-marketing/also-load-patch-2
Browse files Browse the repository at this point in the history
Cast also-load xml attribute to string
  • Loading branch information
alcaeus authored Nov 5, 2019
2 parents 083c3fe + d8dff50 commit a93d030
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 10 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"Doctrine\\ODM\\MongoDB\\Benchmark\\": "benchmark",
"Doctrine\\ODM\\MongoDB\\Tests\\": "tests/Doctrine/ODM/MongoDB/Tests",
"Documents\\": "tests/Documents",
"Stubs\\": "tests/Stubs"
"Stubs\\": "tests/Stubs",
"TestDocuments\\" :"tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/fixtures"
}
},
"extra": {
Expand Down
2 changes: 1 addition & 1 deletion doctrine-mongo-mapping.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
<xs:attribute name="lock" type="xs:boolean" />
<xs:attribute name="not-saved" type="xs:boolean" />
<xs:attribute name="nullable" type="xs:boolean" />
<xs:attribute name="also-load" type="xs:NMTOKEN" />
<xs:attribute name="also-load" type="xs:string" />
<!-- index options -->
<xs:attribute name="background" type="xs:boolean" />
<xs:attribute name="drop-dups" type="xs:boolean" />
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public function loadMetadataForClass($className, ClassMetadata $class)
}

if (isset($attributes['also-load'])) {
$mapping['alsoLoadFields'] = explode(',', $attributes['also-load']);
$mapping['alsoLoadFields'] = explode(',', (string) $attributes['also-load']);
} elseif (isset($attributes['version'])) {
$mapping['version'] = ('true' === (string) $attributes['version']);
} elseif (isset($attributes['lock'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
use TestDocuments\PrimedCollectionDocument;
use PHPUnit\Framework\TestCase;

require_once 'fixtures/InvalidPartialFilterDocument.php';
require_once 'fixtures/PartialFilterDocument.php';
require_once 'fixtures/PrimedCollectionDocument.php';
require_once 'fixtures/User.php';
require_once 'fixtures/EmbeddedDocument.php';
require_once 'fixtures/QueryResultDocument.php';

abstract class AbstractDriverTest extends TestCase
{
protected $driver;
Expand Down
24 changes: 24 additions & 0 deletions tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/XmlDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
use Doctrine\ODM\MongoDB\Mapping\Driver\XmlDriver;
use TestDocuments\AlsoLoadDocument;
use TestDocuments\UserCustomIdGenerator;
use TestDocuments\UserCustomIdGeneratorWithIdField;

Expand Down Expand Up @@ -87,6 +88,29 @@ public function testInvalidPartialFilterExpressions()
],
], $classMetadata->getIndexes());
}

public function testAlsoLoadFieldMapping()
{
$classMetadata = new ClassMetadata(AlsoLoadDocument::class);
$this->driver->loadMetadataForClass(AlsoLoadDocument::class, $classMetadata);

$this->assertEquals(array(
'fieldName' => 'createdAt',
'name' => 'createdAt',
'type' => 'date',
'isCascadeDetach' => false,
'isCascadeMerge' => false,
'isCascadePersist' => false,
'isCascadeRefresh' => false,
'isCascadeRemove' => false,
'isInverseSide' => false,
'isOwningSide' => true,
'nullable' => false,
'strategy' => ClassMetadata::STORAGE_STRATEGY_SET,
'also-load' => 'createdOn,creation_date',
'alsoLoadFields' => array('createdOn', 'creation_date'),
), $classMetadata->fieldMappings['createdAt']);
}
}

namespace TestDocuments;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace TestDocuments;

class AlsoLoadDocument
{
protected $id;

protected $createdAt;

public function __construct()
{
$this->createdAt = new \DateTime();
}

public function getId()
{
return $this->id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?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="TestDocuments\AlsoLoadDocument" db="documents" collection="users">
<field name="id" id="true" />
<field name="createdAt" type="date" also-load="createdOn,creation_date"/>
</document>
</doctrine-mongo-mapping>

0 comments on commit a93d030

Please sign in to comment.