Skip to content

Commit

Permalink
Add ability to chunk relation results
Browse files Browse the repository at this point in the history
Closes #297
  • Loading branch information
stevebauman committed Jun 9, 2021
1 parent 55bcde6 commit 49e7a4b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Models/Relations/HasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace LdapRecord\Models\Relations;

use Closure;
use LdapRecord\DetectsErrors;
use LdapRecord\LdapRecordException;
use LdapRecord\Models\Model;
Expand Down Expand Up @@ -107,6 +108,21 @@ protected function paginateOnceUsing($pageSize)
return $result;
}

/**
* Chunk the relation results using the given callback.
*
* @param int $pageSize
* @param Closure $callback
*
* @return void
*/
public function chunk($pageSize = 1000, Closure $callback)
{
$this->getRelationQuery()->chunk($pageSize, function ($entries) use ($callback) {
$callback($this->transformResults($entries));
});
}

/**
* Get the relationships results.
*
Expand Down

0 comments on commit 49e7a4b

Please sign in to comment.