File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed
src/Jenssegers/Mongodb/Query Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -422,18 +422,28 @@ public function generateCacheKey()
422
422
public function aggregate ($ function , $ columns = [])
423
423
{
424
424
$ this ->aggregate = compact ('function ' , 'columns ' );
425
-
425
+
426
+ $ previousColumns = $ this ->columns ;
427
+
428
+ // We will also back up the select bindings since the select clause will be
429
+ // removed when performing the aggregate function. Once the query is run
430
+ // we will add the bindings back onto this query so they can get used.
431
+ $ previousSelectBindings = $ this ->bindings ['select ' ];
432
+
433
+ $ this ->bindings ['select ' ] = [];
434
+
426
435
$ results = $ this ->get ($ columns );
427
-
436
+
428
437
// Once we have executed the query, we will reset the aggregate property so
429
438
// that more select queries can be executed against the database without
430
439
// the aggregate value getting in the way when the grammar builds it.
431
- $ this ->columns = null ;
432
440
$ this ->aggregate = null ;
433
-
441
+ $ this ->columns = $ previousColumns ;
442
+ $ this ->bindings ['select ' ] = $ previousSelectBindings ;
443
+
434
444
if (isset ($ results [0 ])) {
435
445
$ result = (array ) $ results [0 ];
436
-
446
+
437
447
return $ result ['aggregate ' ];
438
448
}
439
449
}
You can’t perform that action at this time.
0 commit comments