diff --git a/docs/en/02_Developer_Guides/01_Templates/02_Common_Variables.md b/docs/en/02_Developer_Guides/01_Templates/02_Common_Variables.md index 373abdda0..521d6ae5d 100644 --- a/docs/en/02_Developer_Guides/01_Templates/02_Common_Variables.md +++ b/docs/en/02_Developer_Guides/01_Templates/02_Common_Variables.md @@ -328,7 +328,7 @@ When in a particular scope, `$Up` takes the scope back to the previous level. <% end_loop %> Given the following structure, it will output the text. - + My Page | +-+ Child 1 @@ -343,6 +343,16 @@ Given the following structure, it will output the text. Page 'Grandchild 1' is a grandchild of 'My Page' Page 'Child 2' is a child of 'MyPage' +
+Additional selectors implicitely change the scope so you need to put additional `$Up` to get what you expect. +
+ + :::ss +

Children of '$Title'

+ <% loop $Children.Sort('Title').First %> + <%-- We have two additional selectors in the loop expression so... --%> +

Page '$Title' is a child of '$Up.Up.Up.Title'

+ <% end_loop %> ### Top diff --git a/docs/en/02_Developer_Guides/10_Email/index.md b/docs/en/02_Developer_Guides/10_Email/index.md index bb965e92e..059e2a659 100644 --- a/docs/en/02_Developer_Guides/10_Email/index.md +++ b/docs/en/02_Developer_Guides/10_Email/index.md @@ -9,7 +9,7 @@ covers how to create an `Email` instance, customise it with a HTML template, the Out of the box, SilverStripe will use the built-in PHP `mail()` command. If you are not running an SMTP server, you will need to either configure PHP's SMTP settings (see [PHP documentation](http://php.net/mail) to include your mail -server configuration or use one of the third party SMTP services like [Mandrill](https://github.com/lekoala/silverstripe-mandrill) +server configuration or use one of the third party SMTP services like [SparkPost](https://github.com/lekoala/silverstripe-sparkpost) and [Postmark](https://github.com/fullscreeninteractive/silverstripe-postmarkmailer). ## Usage diff --git a/model/DataQuery.php b/model/DataQuery.php index fe7cb7d62..cf8fe839b 100644 --- a/model/DataQuery.php +++ b/model/DataQuery.php @@ -392,7 +392,8 @@ class DataQuery { * automatically so must not contain double quotes. */ public function max($field) { - return $this->aggregate("MAX(\"$field\")"); + $table = ClassInfo::table_for_object_field($this->dataClass, $field); + return $this->aggregate("MAX(\"$table\".\"$field\")"); } /** @@ -402,7 +403,8 @@ class DataQuery { * automatically so must not contain double quotes. */ public function min($field) { - return $this->aggregate("MIN(\"$field\")"); + $table = ClassInfo::table_for_object_field($this->dataClass, $field); + return $this->aggregate("MIN(\"$table\".\"$field\")"); } /** @@ -412,7 +414,8 @@ class DataQuery { * automatically so must not contain double quotes. */ public function avg($field) { - return $this->aggregate("AVG(\"$field\")"); + $table = ClassInfo::table_for_object_field($this->dataClass, $field); + return $this->aggregate("AVG(\"$table\".\"$field\")"); } /** @@ -422,7 +425,8 @@ class DataQuery { * automatically so must not contain double quotes. */ public function sum($field) { - return $this->aggregate("SUM(\"$field\")"); + $table = ClassInfo::table_for_object_field($this->dataClass, $field); + return $this->aggregate("SUM(\"$table\".\"$field\")"); } /** diff --git a/model/Map.php b/model/Map.php index 719625799..f93a1e6e0 100644 --- a/model/Map.php +++ b/model/Map.php @@ -196,7 +196,7 @@ class SS_Map implements ArrayAccess, Countable, IteratorAggregate { } user_error( - "SS_Map is read-only. Please use $map->push($key, $value) to append values", + 'SS_Map is read-only. Please use $map->push($key, $value) to append values', E_USER_ERROR ); } diff --git a/tests/model/DataListTest.php b/tests/model/DataListTest.php index 87a695f17..21299c88e 100755 --- a/tests/model/DataListTest.php +++ b/tests/model/DataListTest.php @@ -363,6 +363,17 @@ class DataListTest extends SapphireTest { $this->assertEquals($otherExpected, $otherMap); } + public function testAmbiguousAggregate() { + // Test that we avoid ambiguity error when a field exists on two joined tables + // Fetch the sponsors in a round-about way to simulate this + $teamID = $this->idFromFixture('DataObjectTest_Team','team2'); + $sponsors = DataObjectTest_EquipmentCompany::get()->filter('SponsoredTeams.ID', $teamID); + $this->assertNotNull($sponsors->Max('ID')); + $this->assertNotNull($sponsors->Min('ID')); + $this->assertNotNull($sponsors->Avg('ID')); + $this->assertNotNull($sponsors->Sum('ID')); + } + public function testEach() { $list = DataObjectTest_TeamComment::get();