Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-mongodb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
laravel-mongodb
Commits
374845a7
Commit
374845a7
authored
Jun 26, 2017
by
Jens Segers
Committed by
GitHub
Jun 26, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1186 from lintaba/patch-2
Aggregation shouldn't mutate querybuilder
parents
03f157ee
f3bc6e45
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
5 deletions
+15
-5
Builder.php
src/Jenssegers/Mongodb/Query/Builder.php
+15
-5
No files found.
src/Jenssegers/Mongodb/Query/Builder.php
View file @
374845a7
...
@@ -422,18 +422,28 @@ class Builder extends BaseBuilder
...
@@ -422,18 +422,28 @@ class Builder extends BaseBuilder
public
function
aggregate
(
$function
,
$columns
=
[])
public
function
aggregate
(
$function
,
$columns
=
[])
{
{
$this
->
aggregate
=
compact
(
'function'
,
'columns'
);
$this
->
aggregate
=
compact
(
'function'
,
'columns'
);
$previousColumns
=
$this
->
columns
;
// We will also back up the select bindings since the select clause will be
// removed when performing the aggregate function. Once the query is run
// we will add the bindings back onto this query so they can get used.
$previousSelectBindings
=
$this
->
bindings
[
'select'
];
$this
->
bindings
[
'select'
]
=
[];
$results
=
$this
->
get
(
$columns
);
$results
=
$this
->
get
(
$columns
);
// Once we have executed the query, we will reset the aggregate property so
// Once we have executed the query, we will reset the aggregate property so
// that more select queries can be executed against the database without
// that more select queries can be executed against the database without
// the aggregate value getting in the way when the grammar builds it.
// the aggregate value getting in the way when the grammar builds it.
$this
->
columns
=
null
;
$this
->
aggregate
=
null
;
$this
->
aggregate
=
null
;
$this
->
columns
=
$previousColumns
;
$this
->
bindings
[
'select'
]
=
$previousSelectBindings
;
if
(
isset
(
$results
[
0
]))
{
if
(
isset
(
$results
[
0
]))
{
$result
=
(
array
)
$results
[
0
];
$result
=
(
array
)
$results
[
0
];
return
$result
[
'aggregate'
];
return
$result
[
'aggregate'
];
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment