Commit eb00a3b8 authored by beberlei's avatar beberlei

[2.0] DDC-195 - Refactored Mapping Syntax again to be arrays in all...

[2.0] DDC-195 - Refactored Mapping Syntax again to be arrays in all annotations, xml and yaml drivers instead of parsing the fields in the AssociationMapping implementations.
parent 5bf16920
...@@ -272,8 +272,12 @@ class XmlDriver extends AbstractFileDriver ...@@ -272,8 +272,12 @@ class XmlDriver extends AbstractFileDriver
$mapping['orphanRemoval'] = (bool)$oneToManyElement->{'orphan-removal'}; $mapping['orphanRemoval'] = (bool)$oneToManyElement->{'orphan-removal'};
} }
if (isset($oneToManyElement['order-by'])) { if (isset($oneToManyElement->{'order-by'})) {
$mapping['orderBy'] = (string)$oneToManyElement['order-by']; $orderBy = array();
foreach ($oneToManyElement->{'order-by'}->{'order-by-field'} AS $orderByField) {
$orderBy[(string)$orderByField['name']] = (string)$orderByField['direction'];
}
$mapping['orderBy'] = $orderBy;
} }
$metadata->mapOneToMany($mapping); $metadata->mapOneToMany($mapping);
...@@ -363,8 +367,12 @@ class XmlDriver extends AbstractFileDriver ...@@ -363,8 +367,12 @@ class XmlDriver extends AbstractFileDriver
$mapping['orphanRemoval'] = (bool)$manyToManyElement->{'orphan-removal'}; $mapping['orphanRemoval'] = (bool)$manyToManyElement->{'orphan-removal'};
} }
if (isset($manyToManyElement['order-by'])) { if (isset($manyToManyElement->{'order-by'})) {
$mapping['orderBy'] = (string)$manyToManyElement['order-by']; $orderBy = array();
foreach ($manyToManyElement->{'order-by'}->{'order-by-field'} AS $orderByField) {
$orderBy[(string)$orderByField['name']] = (string)$orderByField['direction'];
}
$mapping['orderBy'] = $orderBy;
} }
$metadata->mapManyToMany($mapping); $metadata->mapManyToMany($mapping);
......
...@@ -146,18 +146,10 @@ class ManyToManyMapping extends AssociationMapping ...@@ -146,18 +146,10 @@ class ManyToManyMapping extends AssociationMapping
} }
if (isset($mapping['orderBy'])) { if (isset($mapping['orderBy'])) {
$parts = explode(",", $mapping['orderBy']); if (!is_array($mapping['orderBy'])) {
$orderByGroup = array(); throw new \InvalidArgumentException("'orderBy' is expected to be an array, not ".gettype($mapping['orderBy']));
foreach ($parts AS $part) {
$orderByItem = explode(" ", trim($part));
if (count($orderByItem) == 1) {
$orderByGroup[$orderByItem[0]] = "ASC";
} else {
$orderByGroup[$orderByItem[0]] = array_pop($orderByItem);
}
} }
$this->orderBy = $mapping['orderBy'];
$this->orderBy = $orderByGroup;
} }
} }
......
...@@ -86,18 +86,10 @@ class OneToManyMapping extends AssociationMapping ...@@ -86,18 +86,10 @@ class OneToManyMapping extends AssociationMapping
(bool) $mapping['orphanRemoval'] : false; (bool) $mapping['orphanRemoval'] : false;
if (isset($mapping['orderBy'])) { if (isset($mapping['orderBy'])) {
$parts = explode(",", $mapping['orderBy']); if (!is_array($mapping['orderBy'])) {
$orderByGroup = array(); throw new \InvalidArgumentException("'orderBy' is expected to be an array, not ".gettype($mapping['orderBy']));
foreach ($parts AS $part) {
$orderByItem = explode(" ", trim($part));
if (count($orderByItem) == 1) {
$orderByGroup[$orderByItem[0]] = "ASC";
} else {
$orderByGroup[$orderByItem[0]] = array_pop($orderByItem);
}
} }
$this->orderBy = $mapping['orderBy'];
$this->orderBy = $orderByGroup;
} }
} }
......
...@@ -22,13 +22,13 @@ class RoutingRoute ...@@ -22,13 +22,13 @@ class RoutingRoute
* joinColumns={@JoinColumn(name="route_id", referencedColumnName="id")}, * joinColumns={@JoinColumn(name="route_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="leg_id", referencedColumnName="id", unique=true)} * inverseJoinColumns={@JoinColumn(name="leg_id", referencedColumnName="id", unique=true)}
* ) * )
* @OrderBy("departureDate ASC") * @OrderBy({"departureDate" = "ASC"})
*/ */
public $legs; public $legs;
/** /**
* @OneToMany(targetEntity="RoutingRouteBooking", mappedBy="route") * @OneToMany(targetEntity="RoutingRouteBooking", mappedBy="route")
* @OrderBy("passengerName ASC") * @OrderBy({"passengerName" = "ASC"})
*/ */
public $bookings = array(); public $bookings = array();
......
...@@ -97,7 +97,7 @@ abstract class OJTIC_Pet ...@@ -97,7 +97,7 @@ abstract class OJTIC_Pet
/** /**
* @OneToMany(targetEntity="OJTIC_Pet", mappedBy="mother") * @OneToMany(targetEntity="OJTIC_Pet", mappedBy="mother")
* @OrderBy("name ASC") * @OrderBy({"name" = "ASC"})
*/ */
public $children; public $children;
...@@ -106,7 +106,7 @@ abstract class OJTIC_Pet ...@@ -106,7 +106,7 @@ abstract class OJTIC_Pet
* @JoinTable(name="OTJIC_Pet_Friends", * @JoinTable(name="OTJIC_Pet_Friends",
* joinColumns={@JoinColumn(name="pet_id", referencedColumnName="id")}, * joinColumns={@JoinColumn(name="pet_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="friend_id", referencedColumnName="id")}) * inverseJoinColumns={@JoinColumn(name="friend_id", referencedColumnName="id")})
* @OrderBy("name ASC") * @OrderBy({"name" = "ASC"})
*/ */
public $friends; public $friends;
......
...@@ -207,7 +207,7 @@ class User ...@@ -207,7 +207,7 @@ class User
/** /**
* *
* @OneToMany(targetEntity="Phonenumber", mappedBy="user", cascade={"persist"}) * @OneToMany(targetEntity="Phonenumber", mappedBy="user", cascade={"persist"})
* @OrderBy("number ASC") * @OrderBy({"number"="ASC"})
*/ */
public $phonenumbers; public $phonenumbers;
......
...@@ -24,7 +24,10 @@ ...@@ -24,7 +24,10 @@
<join-column name="address_id" referenced-column-name="id"/> <join-column name="address_id" referenced-column-name="id"/>
</one-to-one> </one-to-one>
<one-to-many field="phonenumbers" target-entity="Phonenumber" mapped-by="user" order-by="number ASC"> <one-to-many field="phonenumbers" target-entity="Phonenumber" mapped-by="user">
<order-by>
<order-by-field name="number" direction="ASC" />
</order-by>
<cascade> <cascade>
<cascade-persist/> <cascade-persist/>
</cascade> </cascade>
......
...@@ -27,7 +27,8 @@ Doctrine\Tests\ORM\Mapping\User: ...@@ -27,7 +27,8 @@ Doctrine\Tests\ORM\Mapping\User:
phonenumbers: phonenumbers:
targetEntity: Phonenumber targetEntity: Phonenumber
mappedBy: user mappedBy: user
orderBy: number ASC orderBy:
number: ASC
cascade: [ persist ] cascade: [ persist ]
manyToMany: manyToMany:
groups: groups:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment