mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
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:
parent
160482847c
commit
91068c23b5
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user