diff --git a/core/model/Aggregate.php b/core/model/Aggregate.php index cfb2dbf1e..c3e3e519b 100644 --- a/core/model/Aggregate.php +++ b/core/model/Aggregate.php @@ -87,7 +87,7 @@ class Aggregate extends ViewableData { $table = null; foreach (ClassInfo::ancestry($this->type, true) as $class) { - $fields = DataObject::custom_database_fields($class); + $fields = DataObject::database_fields($class); if (array_key_exists($attribute, $fields)) { $table = $class; break; } } diff --git a/tests/model/AggregateTest.php b/tests/model/AggregateTest.php index 17795ad21..a17fd8ca0 100644 --- a/tests/model/AggregateTest.php +++ b/tests/model/AggregateTest.php @@ -87,6 +87,23 @@ class AggregateTest extends SapphireTest { } /* */ + /** + * Test base-level field access - was failing due to use of custom_database_fields, not just database_fields + * @return unknown_type + */ + function testBaseFieldAggregate() { + $this->assertEquals( + DataObject::Aggregate('AggregateTest_Foo')->Max('LastEdited'), + DataObject::get_one('AggregateTest_Foo', '', '', 'LastEdited DESC')->LastEdited + ); + + $this->assertEquals( + DataObject::Aggregate('AggregateTest_Foo')->Max('Created'), + DataObject::get_one('AggregateTest_Foo', '', '', 'Created DESC')->Created + ); + } + /* */ + /** * Test aggregation takes place on the passed type & it's children only */