mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #6307 from open-sausages/pulls/3.4/fix-aggregrate-error
BUG Fix regression in aggregate column lookup from #6199
This commit is contained in:
commit
d15d80ea2c
@ -298,6 +298,9 @@ class ClassInfo {
|
||||
* field column for a {@link DataObject}. If the field does not exist, this
|
||||
* will return null.
|
||||
*
|
||||
* Note: In 3.x and below this method may return 'DataObject'. From 4.0 onwards
|
||||
* null will be returned if a field is not a member of the object.
|
||||
*
|
||||
* @param string $candidateClass
|
||||
* @param string $fieldName
|
||||
*
|
||||
|
@ -390,9 +390,13 @@ class DataQuery {
|
||||
*
|
||||
* @param String $field Unquoted database column name. Will be ANSI quoted
|
||||
* automatically so must not contain double quotes.
|
||||
* @return string
|
||||
*/
|
||||
public function max($field) {
|
||||
$table = ClassInfo::table_for_object_field($this->dataClass, $field);
|
||||
if (!$table || $table === 'DataObject') {
|
||||
return $this->aggregate("MAX(\"$field\")");
|
||||
}
|
||||
return $this->aggregate("MAX(\"$table\".\"$field\")");
|
||||
}
|
||||
|
||||
@ -401,9 +405,13 @@ class DataQuery {
|
||||
*
|
||||
* @param String $field Unquoted database column name. Will be ANSI quoted
|
||||
* automatically so must not contain double quotes.
|
||||
* @return string
|
||||
*/
|
||||
public function min($field) {
|
||||
$table = ClassInfo::table_for_object_field($this->dataClass, $field);
|
||||
if (!$table || $table === 'DataObject') {
|
||||
return $this->aggregate("MIN(\"$field\")");
|
||||
}
|
||||
return $this->aggregate("MIN(\"$table\".\"$field\")");
|
||||
}
|
||||
|
||||
@ -412,9 +420,13 @@ class DataQuery {
|
||||
*
|
||||
* @param String $field Unquoted database column name. Will be ANSI quoted
|
||||
* automatically so must not contain double quotes.
|
||||
* @return string
|
||||
*/
|
||||
public function avg($field) {
|
||||
$table = ClassInfo::table_for_object_field($this->dataClass, $field);
|
||||
if (!$table || $table === 'DataObject') {
|
||||
return $this->aggregate("AVG(\"$field\")");
|
||||
}
|
||||
return $this->aggregate("AVG(\"$table\".\"$field\")");
|
||||
}
|
||||
|
||||
@ -423,9 +435,13 @@ class DataQuery {
|
||||
*
|
||||
* @param String $field Unquoted database column name. Will be ANSI quoted
|
||||
* automatically so must not contain double quotes.
|
||||
* @return string
|
||||
*/
|
||||
public function sum($field) {
|
||||
$table = ClassInfo::table_for_object_field($this->dataClass, $field);
|
||||
if (!$table || $table === 'DataObject') {
|
||||
return $this->aggregate("SUM(\"$field\")");
|
||||
}
|
||||
return $this->aggregate("SUM(\"$table\".\"$field\")");
|
||||
}
|
||||
|
||||
|
@ -372,6 +372,13 @@ class DataListTest extends SapphireTest {
|
||||
$this->assertNotNull($sponsors->Min('ID'));
|
||||
$this->assertNotNull($sponsors->Avg('ID'));
|
||||
$this->assertNotNull($sponsors->Sum('ID'));
|
||||
|
||||
// Test non-orm many_many_extraFields
|
||||
$company = $this->objFromFixture('DataObjectTest_EquipmentCompany', 'equipmentcompany1');
|
||||
$this->assertNotNull($company->SponsoredTeams()->Max('SponsorFee'));
|
||||
$this->assertNotNull($company->SponsoredTeams()->Min('SponsorFee'));
|
||||
$this->assertNotNull($company->SponsoredTeams()->Avg('SponsorFee'));
|
||||
$this->assertNotNull($company->SponsoredTeams()->Sum('SponsorFee'));
|
||||
}
|
||||
|
||||
public function testEach() {
|
||||
|
Loading…
Reference in New Issue
Block a user