Skip to content

Commit

Permalink
fix more query builder methods
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Apr 10, 2024
1 parent ae6dc85 commit 95ef230
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
Expand Up @@ -1115,6 +1115,29 @@ public function lazyById($chunkSize = 1000, $column = null, $alias = null)
});
}

/**
* Query lazily, by chunking the results of a query by comparing IDs in descending order.
*
* @param int $chunkSize
* @param string|null $column
* @param string|null $alias
* @return \Illuminate\Support\LazyCollection
*/
public function lazyByIdDesc($chunkSize = 1000, $column = null, $alias = null)
{
$column ??= $this->getRelated()->qualifyColumn(
$this->getRelatedKeyName()
);

$alias ??= $this->getRelatedKeyName();

return $this->prepareQueryBuilder()->lazyByIdDesc($chunkSize, $column, $alias)->map(function ($model) {
$this->hydratePivotRelation([$model]);

return $model;
});
}

/**
* Get a lazy collection for the given query.
*
Expand Down
17 changes: 17 additions & 0 deletions src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php
Expand Up @@ -692,6 +692,23 @@ public function lazyById($chunkSize = 1000, $column = null, $alias = null)
return $this->prepareQueryBuilder()->lazyById($chunkSize, $column, $alias);
}

/**
* Query lazily, by chunking the results of a query by comparing IDs in descending order.
*
* @param int $chunkSize
* @param string|null $column
* @param string|null $alias
* @return \Illuminate\Support\LazyCollection
*/
public function lazyByIdDesc($chunkSize = 1000, $column = null, $alias = null)
{
$column ??= $this->getRelated()->getQualifiedKeyName();

$alias ??= $this->getRelated()->getKeyName();

return $this->prepareQueryBuilder()->lazyByIdDesc($chunkSize, $column, $alias);
}

/**
* Prepare the query builder for query execution.
*
Expand Down

1 comment on commit 95ef230

@GromNaN
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up #50991

Please sign in to comment.