mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #2428 from PutmanMedia/pulls/sqlquery-orderby-joins
Only compare array notations in SQLQuery->getOrderedJoins()
This commit is contained in:
commit
c349322b7e
@ -1127,10 +1127,15 @@ class SQLQuery {
|
|||||||
// shift the first FROM table out from so we only deal with the JOINs
|
// shift the first FROM table out from so we only deal with the JOINs
|
||||||
$baseFrom = array_shift($from);
|
$baseFrom = array_shift($from);
|
||||||
$this->mergesort($from, function($firstJoin, $secondJoin) {
|
$this->mergesort($from, function($firstJoin, $secondJoin) {
|
||||||
if($firstJoin['order'] == $secondJoin['order']) {
|
if(
|
||||||
|
!is_array($firstJoin)
|
||||||
|
|| !is_array($secondJoin)
|
||||||
|
|| $firstJoin['order'] == $secondJoin['order']
|
||||||
|
) {
|
||||||
return 0;
|
return 0;
|
||||||
|
} else {
|
||||||
|
return ($firstJoin['order'] < $secondJoin['order']) ? -1 : 1;
|
||||||
}
|
}
|
||||||
return ($firstJoin['order'] < $secondJoin['order']) ? -1 : 1;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Put the first FROM table back into the results
|
// Put the first FROM table back into the results
|
||||||
|
@ -132,10 +132,21 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
$query = new SQLQuery();
|
$query = new SQLQuery();
|
||||||
$query->setFrom("MyTable");
|
$query->setFrom("MyTable");
|
||||||
$query->setOrderBy('RAND()');
|
$query->setOrderBy('RAND()');
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'SELECT *, RAND() AS "_SortColumn0" FROM MyTable ORDER BY "_SortColumn0" ASC',
|
'SELECT *, RAND() AS "_SortColumn0" FROM MyTable ORDER BY "_SortColumn0" ASC',
|
||||||
$query->sql());
|
$query->sql());
|
||||||
|
|
||||||
|
$query = new SQLQuery();
|
||||||
|
$query->setFrom("MyTable");
|
||||||
|
$query->addFrom('INNER JOIN SecondTable USING (ID)');
|
||||||
|
$query->addFrom('INNER JOIN ThirdTable USING (ID)');
|
||||||
|
$query->setOrderBy('MyName');
|
||||||
|
$this->assertEquals(
|
||||||
|
'SELECT * FROM MyTable '
|
||||||
|
. 'INNER JOIN SecondTable USING (ID) '
|
||||||
|
. 'INNER JOIN ThirdTable USING (ID) '
|
||||||
|
. 'ORDER BY MyName ASC',
|
||||||
|
$query->sql());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNullLimit() {
|
public function testNullLimit() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user