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
cc66b3a8
Commit
cc66b3a8
authored
Aug 01, 2019
by
Dan Jones
Committed by
Jens Segers
Aug 01, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get base query before update so that scopes are applied (#1799)
Fixes #1798
parent
b9cc872a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
1 deletion
+39
-1
Builder.php
src/Jenssegers/Mongodb/Eloquent/Builder.php
+1
-1
QueryTest.php
tests/QueryTest.php
+18
-0
Scoped.php
tests/models/Scoped.php
+20
-0
No files found.
src/Jenssegers/Mongodb/Eloquent/Builder.php
View file @
cc66b3a8
...
@@ -44,7 +44,7 @@ class Builder extends EloquentBuilder
...
@@ -44,7 +44,7 @@ class Builder extends EloquentBuilder
return
1
;
return
1
;
}
}
return
$this
->
query
->
update
(
$this
->
addUpdatedAtColumn
(
$values
),
$options
);
return
$this
->
toBase
()
->
update
(
$this
->
addUpdatedAtColumn
(
$values
),
$options
);
}
}
/**
/**
...
...
tests/QueryTest.php
View file @
cc66b3a8
...
@@ -21,6 +21,7 @@ class QueryTest extends TestCase
...
@@ -21,6 +21,7 @@ class QueryTest extends TestCase
public
function
tearDown
()
:
void
public
function
tearDown
()
:
void
{
{
User
::
truncate
();
User
::
truncate
();
Scoped
::
truncate
();
parent
::
tearDown
();
parent
::
tearDown
();
}
}
...
@@ -309,4 +310,21 @@ class QueryTest extends TestCase
...
@@ -309,4 +310,21 @@ class QueryTest extends TestCase
$this
->
assertEquals
(
9
,
$results
->
total
());
$this
->
assertEquals
(
9
,
$results
->
total
());
$this
->
assertEquals
(
1
,
$results
->
currentPage
());
$this
->
assertEquals
(
1
,
$results
->
currentPage
());
}
}
public
function
testUpdate
()
{
$this
->
assertEquals
(
1
,
User
::
where
([
'name'
=>
'John Doe'
])
->
update
([
'name'
=>
'Jim Morrison'
]));
$this
->
assertEquals
(
1
,
User
::
where
([
'name'
=>
'Jim Morrison'
])
->
count
());
Scoped
::
create
([
'favorite'
=>
true
]);
Scoped
::
create
([
'favorite'
=>
false
]);
$this
->
assertCount
(
1
,
Scoped
::
get
());
$this
->
assertEquals
(
1
,
Scoped
::
query
()
->
update
([
'name'
=>
'Johnny'
]));
$this
->
assertCount
(
1
,
Scoped
::
withoutGlobalScopes
()
->
where
([
'name'
=>
'Johnny'
])
->
get
());
$this
->
assertCount
(
2
,
Scoped
::
withoutGlobalScopes
()
->
get
());
$this
->
assertEquals
(
2
,
Scoped
::
withoutGlobalScopes
()
->
update
([
'name'
=>
'Jimmy'
]));
$this
->
assertCount
(
2
,
Scoped
::
withoutGlobalScopes
()
->
where
([
'name'
=>
'Jimmy'
])
->
get
());
}
}
}
tests/models/Scoped.php
0 → 100644
View file @
cc66b3a8
<?php
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\Builder
;
class
Scoped
extends
Eloquent
{
protected
$connection
=
'mongodb'
;
protected
$collection
=
'scoped'
;
protected
$fillable
=
[
'name'
,
'favorite'
];
protected
static
function
boot
()
{
parent
::
boot
();
static
::
addGlobalScope
(
'favorite'
,
function
(
Builder
$builder
)
{
$builder
->
where
(
'favorite'
,
true
);
});
}
}
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