diff --git a/src/ORM/DataList.php b/src/ORM/DataList.php index fbd93412d79..72dfaf02ef2 100644 --- a/src/ORM/DataList.php +++ b/src/ORM/DataList.php @@ -1174,7 +1174,7 @@ public function shuffle() */ public function removeAll() { - foreach ($this as $item) { + foreach ($this->getGenerator() as $item) { $this->remove($item); } return $this; diff --git a/tests/php/ORM/DataListTest.php b/tests/php/ORM/DataListTest.php index 481b4a316cd..dc80aaf40a0 100755 --- a/tests/php/ORM/DataListTest.php +++ b/tests/php/ORM/DataListTest.php @@ -458,6 +458,17 @@ public function testRemoveByID() $this->assertNull($list->byID($id)); } + /** + * Test DataList->removeAll() + */ + public function testRemoveAll() + { + $list = Team::get(); + $this->assertGreaterThan(0, $list->count()); + $list->removeAll(); + $this->assertCount(0, $list); + } + /** * Test DataList->canSortBy() */