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:
Guy Sartorelli 2023-07-10 18:13:03 +12:00
parent d0ca9cfdde
commit 95d1c674a2
No known key found for this signature in database
GPG Key ID: F313E3B9504D496A

View File

@ -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 = [];
}
/**