[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.
This commit is contained in:
parent
5bf169202f
commit
eb00a3b817
@ -272,8 +272,12 @@ class XmlDriver extends AbstractFileDriver
|
||||
$mapping['orphanRemoval'] = (bool)$oneToManyElement->{'orphan-removal'};
|
||||
}
|
||||
|
||||
if (isset($oneToManyElement['order-by'])) {
|
||||
$mapping['orderBy'] = (string)$oneToManyElement['order-by'];
|
||||
if (isset($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);
|
||||
@ -363,8 +367,12 @@ class XmlDriver extends AbstractFileDriver
|
||||
$mapping['orphanRemoval'] = (bool)$manyToManyElement->{'orphan-removal'};
|
||||
}
|
||||
|
||||
if (isset($manyToManyElement['order-by'])) {
|
||||
$mapping['orderBy'] = (string)$manyToManyElement['order-by'];
|
||||
if (isset($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);
|
||||
|
@ -146,18 +146,10 @@ class ManyToManyMapping extends AssociationMapping
|
||||
}
|
||||
|
||||
if (isset($mapping['orderBy'])) {
|
||||
$parts = explode(",", $mapping['orderBy']);
|
||||
$orderByGroup = array();
|
||||
foreach ($parts AS $part) {
|
||||
$orderByItem = explode(" ", trim($part));
|
||||
if (count($orderByItem) == 1) {
|
||||
$orderByGroup[$orderByItem[0]] = "ASC";
|
||||
} else {
|
||||
$orderByGroup[$orderByItem[0]] = array_pop($orderByItem);
|
||||
}
|
||||
if (!is_array($mapping['orderBy'])) {
|
||||
throw new \InvalidArgumentException("'orderBy' is expected to be an array, not ".gettype($mapping['orderBy']));
|
||||
}
|
||||
|
||||
$this->orderBy = $orderByGroup;
|
||||
$this->orderBy = $mapping['orderBy'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,18 +86,10 @@ class OneToManyMapping extends AssociationMapping
|
||||
(bool) $mapping['orphanRemoval'] : false;
|
||||
|
||||
if (isset($mapping['orderBy'])) {
|
||||
$parts = explode(",", $mapping['orderBy']);
|
||||
$orderByGroup = array();
|
||||
foreach ($parts AS $part) {
|
||||
$orderByItem = explode(" ", trim($part));
|
||||
if (count($orderByItem) == 1) {
|
||||
$orderByGroup[$orderByItem[0]] = "ASC";
|
||||
} else {
|
||||
$orderByGroup[$orderByItem[0]] = array_pop($orderByItem);
|
||||
}
|
||||
if (!is_array($mapping['orderBy'])) {
|
||||
throw new \InvalidArgumentException("'orderBy' is expected to be an array, not ".gettype($mapping['orderBy']));
|
||||
}
|
||||
|
||||
$this->orderBy = $orderByGroup;
|
||||
$this->orderBy = $mapping['orderBy'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,13 +22,13 @@ class RoutingRoute
|
||||
* joinColumns={@JoinColumn(name="route_id", referencedColumnName="id")},
|
||||
* inverseJoinColumns={@JoinColumn(name="leg_id", referencedColumnName="id", unique=true)}
|
||||
* )
|
||||
* @OrderBy("departureDate ASC")
|
||||
* @OrderBy({"departureDate" = "ASC"})
|
||||
*/
|
||||
public $legs;
|
||||
|
||||
/**
|
||||
* @OneToMany(targetEntity="RoutingRouteBooking", mappedBy="route")
|
||||
* @OrderBy("passengerName ASC")
|
||||
* @OrderBy({"passengerName" = "ASC"})
|
||||
*/
|
||||
public $bookings = array();
|
||||
|
||||
|
@ -97,7 +97,7 @@ abstract class OJTIC_Pet
|
||||
|
||||
/**
|
||||
* @OneToMany(targetEntity="OJTIC_Pet", mappedBy="mother")
|
||||
* @OrderBy("name ASC")
|
||||
* @OrderBy({"name" = "ASC"})
|
||||
*/
|
||||
public $children;
|
||||
|
||||
@ -106,7 +106,7 @@ abstract class OJTIC_Pet
|
||||
* @JoinTable(name="OTJIC_Pet_Friends",
|
||||
* joinColumns={@JoinColumn(name="pet_id", referencedColumnName="id")},
|
||||
* inverseJoinColumns={@JoinColumn(name="friend_id", referencedColumnName="id")})
|
||||
* @OrderBy("name ASC")
|
||||
* @OrderBy({"name" = "ASC"})
|
||||
*/
|
||||
public $friends;
|
||||
|
||||
|
@ -207,7 +207,7 @@ class User
|
||||
/**
|
||||
*
|
||||
* @OneToMany(targetEntity="Phonenumber", mappedBy="user", cascade={"persist"})
|
||||
* @OrderBy("number ASC")
|
||||
* @OrderBy({"number"="ASC"})
|
||||
*/
|
||||
public $phonenumbers;
|
||||
|
||||
|
@ -24,7 +24,10 @@
|
||||
<join-column name="address_id" referenced-column-name="id"/>
|
||||
</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-persist/>
|
||||
</cascade>
|
||||
|
@ -27,7 +27,8 @@ Doctrine\Tests\ORM\Mapping\User:
|
||||
phonenumbers:
|
||||
targetEntity: Phonenumber
|
||||
mappedBy: user
|
||||
orderBy: number ASC
|
||||
orderBy:
|
||||
number: ASC
|
||||
cascade: [ persist ]
|
||||
manyToMany:
|
||||
groups:
|
||||
|
Loading…
x
Reference in New Issue
Block a user