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()
422422 public function aggregate ($ function , $ columns = [])
423423 {
424424 $ 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+
426435 $ results = $ this ->get ($ columns );
427-
436+
428437 // Once we have executed the query, we will reset the aggregate property so
429438 // that more select queries can be executed against the database without
430439 // the aggregate value getting in the way when the grammar builds it.
431- $ this ->columns = null ;
432440 $ this ->aggregate = null ;
433-
441+ $ this ->columns = $ previousColumns ;
442+ $ this ->bindings ['select ' ] = $ previousSelectBindings ;
443+
434444 if (isset ($ results [0 ])) {
435445 $ result = (array ) $ results [0 ];
436-
446+
437447 return $ result ['aggregate ' ];
438448 }
439449 }
You can’t perform that action at this time.
0 commit comments