Skip to content

Commit

Permalink
Fix default value of one-to-many order-by to ASC, doctrine#7141
Browse files Browse the repository at this point in the history
  • Loading branch information
Awkan committed Mar 21, 2018
1 parent 87ee409 commit 45b8089
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,10 @@ public function loadMetadataForClass($className, ClassMetadata $metadata)
if (isset($oneToManyElement->{'order-by'})) {
$orderBy = [];
foreach ($oneToManyElement->{'order-by'}->{'order-by-field'} as $orderByField) {
$orderBy[(string) $orderByField['name']] = (string) $orderByField['direction'];
$orderBy[(string) $orderByField['name']] = isset($orderByField['direction'])
? (string) $orderByField['direction']
: 'ASC'
;
}
$mapping['orderBy'] = $orderBy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<one-to-many field="attractions" target-entity="Doctrine\Tests\Models\Cache\Attraction" mapped-by="city">
<cache usage="READ_ONLY" />
<order-by>
<order-by-field name="name" direction="ASC"/>
<order-by-field name="name"/>
</order-by>
</one-to-many>
<many-to-one field="state" target-entity="Doctrine\Tests\Models\Cache\State" inversed-by="cities">
Expand All @@ -20,4 +20,4 @@
</many-to-one>
<many-to-many field="travels" target-entity="Doctrine\Tests\Models\Cache\Travel" mapped-by="visitedCities"/>
</entity>
</doctrine-mapping>
</doctrine-mapping>
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<cascade-persist/>
</cascade>
<order-by>
<order-by-field name="number" direction="ASC" />
<order-by-field name="number" />
</order-by>
</one-to-many>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<cascade-merge/>
</cascade>
<order-by>
<order-by-field name="number" direction="ASC" />
<order-by-field name="number" />
</order-by>
</one-to-many>

Expand Down

0 comments on commit 45b8089

Please sign in to comment.