DataMapper


Refresh All

Refresh All is really only used in one scenario. For example, if you get a number of object, loop through its all list, and delete one or more records, but not all of them. Refresh All will do just that, refresh the all list so the deleted items are removed. We're not able to dynamically remove them from the all list while you're looping through it as that would cause issues with the loop itself. Here's an example of when you'd use refresh_all():

// Get a number of books from the year 2000
$b = new Book();
$b->where('year', 2000)->get();

// Loop through the all list and delete those that are fiction
foreach ($b->all as $book)
{
    if ($book->fiction)
    {
        $book->delete();
    }
}

// Refresh the book objects all list to remove the deleted entries (which are simply empty entries in the all list now)
$b->refresh_all();

// Now we can loop through the all list again looking at only existing objects
foreach ($b->all as $book)
{
    echo $book->name ."<br />";
}

Alternatively, you could instead run your get query again but that will execute a database call whereas Refresh All just removes empty records from the objects all list.