mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX Allow multiple iterations of eager-loaded DataLists
Includes making sure toArray() uses the correct iteration logic, and cloning resets the eagerloaded data for the new clone. Previously, a second iteration would add every relation item to the relation list a second time - so with each iteration your relation list count doubled (though it was the same records time and again).
This commit is contained in:
parent
d0ca9cfdde
commit
95d1c674a2
@ -96,6 +96,7 @@ class DataList extends ViewableData implements SS_List, Filterable, Sortable, Li
|
||||
{
|
||||
$this->dataQuery = clone $this->dataQuery;
|
||||
$this->finalisedQuery = null;
|
||||
$this->eagerLoadedData = [];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -831,11 +832,10 @@ class DataList extends ViewableData implements SS_List, Filterable, Sortable, Li
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
$rows = $this->executeQuery();
|
||||
$results = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$results[] = $this->createDataObject($row);
|
||||
foreach ($this as $item) {
|
||||
$results[] = $item;
|
||||
}
|
||||
|
||||
return $results;
|
||||
@ -1001,6 +1001,7 @@ class DataList extends ViewableData implements SS_List, Filterable, Sortable, Li
|
||||
|
||||
// Re-set the finaliseQuery so that it can be re-executed
|
||||
$this->finalisedQuery = null;
|
||||
$this->eagerLoadedData = [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user