From 91068c23b5cb448fe63ae9f40875a8f0818dbe1f Mon Sep 17 00:00:00 2001 From: Al Twohill Date: Thu, 5 Jul 2018 21:26:31 +1200 Subject: [PATCH] FIX Make column query not distinct When selecting a column, it doesn't make sense to have it distinct. As an alternative, the API could be changed to give the end user the option (eg `->column($field, $distinct = false)`) However if we did that, we would need to make sure we do something similar with `SilverStripe\ORM\UnsavedRelationList` to ensure consistency. --- src/ORM/DataQuery.php | 1 + tests/php/ORM/DataQueryTest.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/ORM/DataQuery.php b/src/ORM/DataQuery.php index e403f90b3..f953aca35 100644 --- a/src/ORM/DataQuery.php +++ b/src/ORM/DataQuery.php @@ -1147,6 +1147,7 @@ class DataQuery { $fieldExpression = $this->expressionForField($field); $query = $this->getFinalisedQuery(array($field)); + $query->setDistinct(false); $originalSelect = $query->getSelect(); $query->setSelect(array()); $query->selectField($fieldExpression, $field); diff --git a/tests/php/ORM/DataQueryTest.php b/tests/php/ORM/DataQueryTest.php index b9278a496..8f2b2a3fd 100644 --- a/tests/php/ORM/DataQueryTest.php +++ b/tests/php/ORM/DataQueryTest.php @@ -379,4 +379,22 @@ class DataQueryTest extends SapphireTest $this->assertEquals('Last', $second['Title']); $this->assertEmpty(array_shift($arrayResult)); } + + public function testColumnReturnsAllValues() + { + $first = new DataQueryTest\ObjectA(); + $first->Name = 'Bar'; + $first->write(); + + $second = new DataQueryTest\ObjectA(); + $second->Name = 'Foo'; + $second->write(); + + $third = new DataQueryTest\ObjectA(); + $third->Name = 'Bar'; + $third->write(); + + $result = DataQueryTest\ObjectA::get()->column('Name'); + $this->assertEquals(['Bar', 'Foo', 'Bar'], $result); + } }