merged git@github.com:SammyK/doctrine2.git:many-to-many-order-by-fix
This commit is contained in:
parent
f0accca99d
commit
0adeade045
@ -278,6 +278,8 @@ class ManyToManyPersister extends AbstractCollectionPersister
|
|||||||
. implode(' AND ', $onConditions)
|
. implode(' AND ', $onConditions)
|
||||||
. ' WHERE ' . implode(' AND ', $whereClauses);
|
. ' WHERE ' . implode(' AND ', $whereClauses);
|
||||||
|
|
||||||
|
$sql .= $this->getOrderingSql($criteria);
|
||||||
|
|
||||||
$stmt = $this->conn->executeQuery($sql, $params);
|
$stmt = $this->conn->executeQuery($sql, $params);
|
||||||
|
|
||||||
return $this
|
return $this
|
||||||
@ -740,4 +742,22 @@ class ManyToManyPersister extends AbstractCollectionPersister
|
|||||||
|
|
||||||
return $types;
|
return $types;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Criteria $criteria
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function getOrderingSql(Criteria $criteria)
|
||||||
|
{
|
||||||
|
$orderings = $criteria->getOrderings();
|
||||||
|
if ($orderings) {
|
||||||
|
$orderBy = [];
|
||||||
|
foreach ($orderings as $field => $direction) {
|
||||||
|
$orderBy[] = $field . ' ' . $direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ' ORDER BY ' . implode(', ', $orderBy);
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -377,6 +377,44 @@ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCa
|
|||||||
$this->assertEquals(0, count($user->groups));
|
$this->assertEquals(0, count($user->groups));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-3952
|
||||||
|
*/
|
||||||
|
public function testManyToManyOrderByIsNotIgnored()
|
||||||
|
{
|
||||||
|
$user = $this->addCmsUserGblancoWithGroups(1);
|
||||||
|
|
||||||
|
$group = new CmsGroup;
|
||||||
|
$group->name = 'C';
|
||||||
|
$user->addGroup($group);
|
||||||
|
|
||||||
|
$group = new CmsGroup;
|
||||||
|
$group->name = 'A';
|
||||||
|
$user->addGroup($group);
|
||||||
|
|
||||||
|
$group = new CmsGroup;
|
||||||
|
$group->name = 'B';
|
||||||
|
$user->addGroup($group);
|
||||||
|
|
||||||
|
$this->_em->persist($user);
|
||||||
|
$this->_em->flush();
|
||||||
|
|
||||||
|
$this->_em->clear();
|
||||||
|
|
||||||
|
$user = $this->_em->find(get_class($user), $user->id);
|
||||||
|
|
||||||
|
$criteria = Criteria::create()
|
||||||
|
->orderBy(['name' => Criteria::ASC]);
|
||||||
|
$groups = $user->getGroups()->matching($criteria);
|
||||||
|
|
||||||
|
$existingOrder = [];
|
||||||
|
foreach ($groups as $group) {
|
||||||
|
$existingOrder[] = $group->getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEquals(['A', 'B', 'C', 'Developers_0'], $existingOrder);
|
||||||
|
}
|
||||||
|
|
||||||
public function testMatching()
|
public function testMatching()
|
||||||
{
|
{
|
||||||
$user = $this->addCmsUserGblancoWithGroups(2);
|
$user = $this->addCmsUserGblancoWithGroups(2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user