Skip to content

Commit 95ef230

Browse files
committed
fix more query builder methods
1 parent ae6dc85 commit 95ef230

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,29 @@ public function lazyById($chunkSize = 1000, $column = null, $alias = null)
11151115
});
11161116
}
11171117

1118+
/**
1119+
* Query lazily, by chunking the results of a query by comparing IDs in descending order.
1120+
*
1121+
* @param int $chunkSize
1122+
* @param string|null $column
1123+
* @param string|null $alias
1124+
* @return \Illuminate\Support\LazyCollection
1125+
*/
1126+
public function lazyByIdDesc($chunkSize = 1000, $column = null, $alias = null)
1127+
{
1128+
$column ??= $this->getRelated()->qualifyColumn(
1129+
$this->getRelatedKeyName()
1130+
);
1131+
1132+
$alias ??= $this->getRelatedKeyName();
1133+
1134+
return $this->prepareQueryBuilder()->lazyByIdDesc($chunkSize, $column, $alias)->map(function ($model) {
1135+
$this->hydratePivotRelation([$model]);
1136+
1137+
return $model;
1138+
});
1139+
}
1140+
11181141
/**
11191142
* Get a lazy collection for the given query.
11201143
*

src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,23 @@ public function lazyById($chunkSize = 1000, $column = null, $alias = null)
692692
return $this->prepareQueryBuilder()->lazyById($chunkSize, $column, $alias);
693693
}
694694

695+
/**
696+
* Query lazily, by chunking the results of a query by comparing IDs in descending order.
697+
*
698+
* @param int $chunkSize
699+
* @param string|null $column
700+
* @param string|null $alias
701+
* @return \Illuminate\Support\LazyCollection
702+
*/
703+
public function lazyByIdDesc($chunkSize = 1000, $column = null, $alias = null)
704+
{
705+
$column ??= $this->getRelated()->getQualifiedKeyName();
706+
707+
$alias ??= $this->getRelated()->getKeyName();
708+
709+
return $this->prepareQueryBuilder()->lazyByIdDesc($chunkSize, $column, $alias);
710+
}
711+
695712
/**
696713
* Prepare the query builder for query execution.
697714
*

0 commit comments

Comments
 (0)