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
274a31da
Commit
274a31da
authored
Aug 10, 2014
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clone query instances for embedded relations
parent
a0acb263
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
4 deletions
+30
-4
EmbedsMany.php
src/Jenssegers/Mongodb/Relations/EmbedsMany.php
+1
-1
EmbedsOne.php
src/Jenssegers/Mongodb/Relations/EmbedsOne.php
+1
-1
EmbedsOneOrMany.php
src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php
+24
-1
EmbeddedRelationsTest.php
tests/EmbeddedRelationsTest.php
+4
-1
No files found.
src/Jenssegers/Mongodb/Relations/EmbedsMany.php
View file @
274a31da
...
...
@@ -99,7 +99,7 @@ class EmbedsMany extends EmbedsOneOrMany {
// Get the correct foreign key value.
$foreignKey
=
$this
->
getForeignKeyValue
(
$model
);
$result
=
$this
->
query
->
pull
(
$this
->
localKey
,
array
(
$model
->
getKeyName
()
=>
$foreignKey
));
$result
=
$this
->
getBaseQuery
()
->
pull
(
$this
->
localKey
,
array
(
$model
->
getKeyName
()
=>
$foreignKey
));
if
(
$result
)
$this
->
dissociate
(
$model
);
...
...
src/Jenssegers/Mongodb/Relations/EmbedsOne.php
View file @
274a31da
...
...
@@ -90,7 +90,7 @@ class EmbedsOne extends EmbedsOneOrMany {
}
// Overwrite the local key with an empty array.
$result
=
$this
->
query
->
update
(
array
(
$this
->
localKey
=>
null
));
$result
=
$this
->
getBaseQuery
()
->
update
(
array
(
$this
->
localKey
=>
null
));
// Detach the model from its parent.
if
(
$result
)
$this
->
dissociate
();
...
...
src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php
View file @
274a31da
...
...
@@ -52,7 +52,6 @@ abstract class EmbedsOneOrMany extends Relation {
// If this is a nested relation, we need to get the parent query instead.
if
(
$parentRelation
=
$this
->
getParentRelation
())
{
//$this->query = $parentRelation->parent->newQuery();
$this
->
query
=
$parentRelation
->
getQuery
();
}
...
...
@@ -330,6 +329,30 @@ abstract class EmbedsOneOrMany extends Relation {
return
$this
->
parent
->
getParentRelation
();
}
/**
* Get the underlying query for the relation.
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public
function
getQuery
()
{
// Because we are sharing this relation instance to models, we need
// to make sure we use separate query instances.
return
clone
$this
->
query
;
}
/**
* Get the base query builder driving the Eloquent builder.
*
* @return \Illuminate\Database\Query\Builder
*/
public
function
getBaseQuery
()
{
// Because we are sharing this relation instance to models, we need
// to make sure we use separate query instances.
return
clone
$this
->
query
->
getQuery
();
}
/**
* Check if this relation is nested in another relation.
*
...
...
tests/EmbeddedRelationsTest.php
View file @
274a31da
...
...
@@ -690,9 +690,12 @@ class EmbeddedRelationsTest extends TestCase {
$user
=
User
::
where
(
'name'
,
'John Doe'
)
->
first
();
$this
->
assertEquals
(
6
,
$user
->
addresses
()
->
first
()
->
visited
);
$user
=
User
::
where
(
'name'
,
'John Doe'
)
->
first
();
$address
=
$user
->
addresses
()
->
first
();
$address
->
decrement
(
'visited'
);
$this
->
assertEquals
(
5
,
$address
->
visited
);
//$this->assertEquals(5, $user->addresses()->first()->visited); TODO
$this
->
assertEquals
(
5
,
$user
->
addresses
()
->
first
()
->
visited
);
$user
=
User
::
where
(
'name'
,
'John Doe'
)
->
first
();
$this
->
assertEquals
(
5
,
$user
->
addresses
()
->
first
()
->
visited
);
...
...
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