File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 5
5
namespace Tpetry \PostgresqlEnhanced \Eloquent \Mixins ;
6
6
7
7
use Closure ;
8
+ use Generator ;
8
9
use Illuminate \Database \Eloquent \Model ;
9
10
use Illuminate \Support \LazyCollection ;
10
11
@@ -15,8 +16,17 @@ public function lazyByCursor(): Closure
15
16
{
16
17
return function (int $ chunkSize = 1000 ): LazyCollection {
17
18
/* @var \Illuminate\Database\Eloquent\Builder $this */
18
- return $ this ->applyScopes ()->getQuery ()->lazyByCursor ($ chunkSize )->map (function (object $ record ): Model {
19
- return $ this ->newModelInstance ()->newFromBuilder ((array ) $ record );
19
+ return new LazyCollection (function () use ($ chunkSize ): Generator {
20
+ foreach ($ this ->applyScopes ()->getQuery ()->lazyByCursor ($ chunkSize )->chunk ($ chunkSize ) as $ items ) {
21
+ $ models = $ this ->getModel ()->hydrate ($ items ->all ())->all ();
22
+ if (count ($ models ) > 0 ) {
23
+ $ models = $ this ->eagerLoadRelations ($ models );
24
+ }
25
+
26
+ foreach ($ models as $ model ) {
27
+ yield $ model ;
28
+ }
29
+ }
20
30
});
21
31
};
22
32
}
You can’t perform that action at this time.
0 commit comments