mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX: Fixed ordering by aggregate columns for DataObject::get() calls with joins. (from r103620)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112155 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
2c4b07ace7
commit
8da5de8d41
@ -2650,10 +2650,13 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
$query->from[] = $join;
|
$query->from[] = $join;
|
||||||
// In order to group by unique columns we have to group by everything listed in the select
|
// In order to group by unique columns we have to group by everything listed in the select
|
||||||
foreach($query->select as $field) {
|
foreach($query->select as $field) {
|
||||||
|
// Skip the _SortColumns; these are only going to be aggregate functions
|
||||||
|
if(preg_match('/AS\s+\"?_SortColumn/', $field, $matches)) {
|
||||||
|
|
||||||
// Identify columns with aliases, and ignore the alias. Making use of the alias in
|
// Identify columns with aliases, and ignore the alias. Making use of the alias in
|
||||||
// group by was causing problems when those queries were subsequently passed into
|
// group by was causing problems when those queries were subsequently passed into
|
||||||
// SQLQuery::unlimitedRowCount.
|
// SQLQuery::unlimitedRowCount.
|
||||||
if(preg_match('/^(.*)\s+AS\s+(\"[^"]+\")\s*$/', $field, $matches)) {
|
} else if(preg_match('/^(.*)\s+AS\s+(\"[^"]+\")\s*$/', $field, $matches)) {
|
||||||
$query->groupby[] = $matches[1];
|
$query->groupby[] = $matches[1];
|
||||||
// Otherwise just use the field as is
|
// Otherwise just use the field as is
|
||||||
} else {
|
} else {
|
||||||
|
@ -738,6 +738,10 @@ class DataObjectTest extends SapphireTest {
|
|||||||
$player = $newTeam->Players()->First();
|
$player = $newTeam->Players()->First();
|
||||||
$this->assertEquals('Sam', $player->FirstName);
|
$this->assertEquals('Sam', $player->FirstName);
|
||||||
$this->assertEquals("Prop", $player->Position);
|
$this->assertEquals("Prop", $player->Position);
|
||||||
|
|
||||||
|
// Check that ordering a many-many relation by an aggregate column doesn't fail
|
||||||
|
$player = $this->objFromFixture('DataObjectTest_Player', 'player2');
|
||||||
|
$player->Teams("", "count(DISTINCT \"DataObjectTest_Team_Players\".\"DataObjectTest_PlayerID\") DESC");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user