Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[XML] Fix default value of many-to-many order-by to ASC #7317

Merged
merged 1 commit into from
Nov 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,9 @@ public function loadMetadataForClass($className, ClassMetadata $metadata)
if (isset($manyToManyElement->{'order-by'})) {
$orderBy = [];
foreach ($manyToManyElement->{'order-by'}->{'order-by-field'} as $orderByField) {
$orderBy[(string) $orderByField['name']] = (string) $orderByField['direction'];
$orderBy[(string) $orderByField['name']] = isset($orderByField['direction'])
? (string) $orderByField['direction']
: Criteria::ASC;
}
$mapping['orderBy'] = $orderBy;
}
Expand Down
15 changes: 15 additions & 0 deletions tests/Doctrine/Tests/Models/GH7316/GH7316Article.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Doctrine\Tests\Models\GH7316;

use Doctrine\Common\Collections\ArrayCollection;

class GH7316Article
{
private $tags;

public function __construct()
{
$this->tags = new ArrayCollection();
}
}
15 changes: 15 additions & 0 deletions tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Doctrine\Tests\Models\DDC889\DDC889Class;
use Doctrine\Tests\Models\Generic\SerializationModel;
use Doctrine\Tests\Models\GH7141\GH7141Article;
use Doctrine\Tests\Models\GH7316\GH7316Article;
use Doctrine\Tests\Models\ValueObjects\Name;
use Doctrine\Tests\Models\ValueObjects\Person;

Expand Down Expand Up @@ -194,6 +195,20 @@ public function testOneToManyDefaultOrderByAsc()
);
}

public function testManyToManyDefaultOrderByAsc() : void
{
$class = new ClassMetadata(GH7316Article::class);
$class->initializeReflection(new RuntimeReflectionService());

$driver = $this->_loadDriver();
$driver->loadMetadataForClass(GH7316Article::class, $class);

self::assertEquals(
Criteria::ASC,
$class->getMetadataValue('associationMappings')['tags']['orderBy']['position']
);
}

/**
* @group DDC-889
* @expectedException \Doctrine\Common\Persistence\Mapping\MappingException
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<entity name="Doctrine\Tests\Models\GH7316\GH7316Article">
<many-to-many field="tags" target-entity="NoTargetEntity" mapped-by="noMappedByField">
<order-by>
<order-by-field name="position"/>
</order-by>
</many-to-many>
</entity>
</doctrine-mapping>