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
fa4a5351
Commit
fa4a5351
authored
Feb 26, 2017
by
wppd
Committed by
Jens Segers
Feb 26, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix query builder delete (#1130)
* fix query builder delete * tweak a bit * tweak the test
parent
163f7260
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
0 deletions
+41
-0
Builder.php
src/Jenssegers/Mongodb/Query/Builder.php
+7
-0
QueryBuilderTest.php
tests/QueryBuilderTest.php
+34
-0
No files found.
src/Jenssegers/Mongodb/Query/Builder.php
View file @
fa4a5351
...
...
@@ -611,6 +611,13 @@ class Builder extends BaseBuilder
*/
public
function
delete
(
$id
=
null
)
{
// If an ID is passed to the method, we will set the where clause to check
// the ID to allow developers to simply and quickly remove a single row
// from their database without manually specifying the where clauses.
if
(
!
is_null
(
$id
))
{
$this
->
where
(
'_id'
,
'='
,
$id
);
}
$wheres
=
$this
->
compileWheres
();
$result
=
$this
->
collection
->
DeleteMany
(
$wheres
);
if
(
1
==
(
int
)
$result
->
isAcknowledged
())
{
...
...
tests/QueryBuilderTest.php
View file @
fa4a5351
...
...
@@ -11,6 +11,40 @@ class QueryBuilderTest extends TestCase
DB
::
collection
(
'items'
)
->
truncate
();
}
public
function
testDeleteWithId
()
{
$user
=
DB
::
collection
(
'users'
)
->
insertGetId
([
[
'name'
=>
'Jane Doe'
,
'age'
=>
20
],
]);
$user_id
=
(
string
)
$user
;
DB
::
collection
(
'items'
)
->
insert
([
[
'name'
=>
'one thing'
,
'user_id'
=>
$user_id
],
[
'name'
=>
'last thing'
,
'user_id'
=>
$user_id
],
[
'name'
=>
'another thing'
,
'user_id'
=>
$user_id
],
[
'name'
=>
'one more thing'
,
'user_id'
=>
$user_id
],
]);
$product
=
DB
::
collection
(
'items'
)
->
first
();
$pid
=
(
string
)
(
$product
[
'_id'
]);
DB
::
collection
(
'items'
)
->
where
(
'user_id'
,
$user_id
)
->
delete
(
$pid
);
$this
->
assertEquals
(
3
,
DB
::
collection
(
'items'
)
->
count
());
$product
=
DB
::
collection
(
'items'
)
->
first
();
$pid
=
$product
[
'_id'
];
DB
::
collection
(
'items'
)
->
where
(
'user_id'
,
$user_id
)
->
delete
(
$pid
);
DB
::
collection
(
'items'
)
->
where
(
'user_id'
,
$user_id
)
->
delete
(
str_random
(
32
));
$this
->
assertEquals
(
2
,
DB
::
collection
(
'items'
)
->
count
());
}
public
function
testCollection
()
{
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Query\Builder'
,
DB
::
collection
(
'users'
));
...
...
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