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:
Daniel Hensby 2016-11-09 22:44:23 +00:00 committed by GitHub
commit d15d80ea2c
3 changed files with 26 additions and 0 deletions

View File

@ -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
*

View File

@ -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\")");
}

View File

@ -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() {