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.
This commit is contained in:
Al Twohill 2018-07-05 21:26:31 +12:00 committed by Daniel Hensby
parent 160482847c
commit 91068c23b5
No known key found for this signature in database
GPG Key ID: D8DEBC4C8E7BC8B9
2 changed files with 19 additions and 0 deletions

View File

@ -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);

View File

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