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
79ea62d0
Commit
79ea62d0
authored
Feb 02, 2018
by
milanspv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
do not use array dot notation for updating embedded models
parent
1bb259ae
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
6 deletions
+20
-6
EmbedsMany.php
src/Jenssegers/Mongodb/Relations/EmbedsMany.php
+1
-3
EmbedsOne.php
src/Jenssegers/Mongodb/Relations/EmbedsOne.php
+1
-3
EmbedsOneOrMany.php
src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php
+18
-0
No files found.
src/Jenssegers/Mongodb/Relations/EmbedsMany.php
View file @
79ea62d0
...
@@ -6,7 +6,6 @@ use Illuminate\Database\Eloquent\Collection;
...
@@ -6,7 +6,6 @@ use Illuminate\Database\Eloquent\Collection;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Pagination\LengthAwarePaginator
;
use
Illuminate\Pagination\LengthAwarePaginator
;
use
Illuminate\Pagination\Paginator
;
use
Illuminate\Pagination\Paginator
;
use
Illuminate\Support\Arr
;
use
MongoDB\BSON\ObjectID
;
use
MongoDB\BSON\ObjectID
;
class
EmbedsMany
extends
EmbedsOneOrMany
class
EmbedsMany
extends
EmbedsOneOrMany
...
@@ -79,8 +78,7 @@ class EmbedsMany extends EmbedsOneOrMany
...
@@ -79,8 +78,7 @@ class EmbedsMany extends EmbedsOneOrMany
// Get the correct foreign key value.
// Get the correct foreign key value.
$foreignKey
=
$this
->
getForeignKeyValue
(
$model
);
$foreignKey
=
$this
->
getForeignKeyValue
(
$model
);
// Use array dot notation for better update behavior.
$values
=
$this
->
getUpdateValues
(
$model
->
getDirty
(),
$this
->
localKey
.
'.$.'
);
$values
=
Arr
::
dot
(
$model
->
getDirty
(),
$this
->
localKey
.
'.$.'
);
// Update document in database.
// Update document in database.
$result
=
$this
->
getBaseQuery
()
->
where
(
$this
->
localKey
.
'.'
.
$model
->
getKeyName
(),
$foreignKey
)
$result
=
$this
->
getBaseQuery
()
->
where
(
$this
->
localKey
.
'.'
.
$model
->
getKeyName
(),
$foreignKey
)
...
...
src/Jenssegers/Mongodb/Relations/EmbedsOne.php
View file @
79ea62d0
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
namespace
Jenssegers\Mongodb\Relations
;
namespace
Jenssegers\Mongodb\Relations
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Support\Arr
;
use
MongoDB\BSON\ObjectID
;
use
MongoDB\BSON\ObjectID
;
class
EmbedsOne
extends
EmbedsOneOrMany
class
EmbedsOne
extends
EmbedsOneOrMany
...
@@ -71,8 +70,7 @@ class EmbedsOne extends EmbedsOneOrMany
...
@@ -71,8 +70,7 @@ class EmbedsOne extends EmbedsOneOrMany
return
$this
->
parent
->
save
();
return
$this
->
parent
->
save
();
}
}
// Use array dot notation for better update behavior.
$values
=
$this
->
getUpdateValues
(
$model
->
getDirty
(),
$this
->
localKey
.
'.'
);
$values
=
Arr
::
dot
(
$model
->
getDirty
(),
$this
->
localKey
.
'.'
);
$result
=
$this
->
getBaseQuery
()
->
update
(
$values
);
$result
=
$this
->
getBaseQuery
()
->
update
(
$values
);
...
...
src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php
View file @
79ea62d0
...
@@ -375,4 +375,22 @@ abstract class EmbedsOneOrMany extends Relation
...
@@ -375,4 +375,22 @@ abstract class EmbedsOneOrMany extends Relation
{
{
return
$this
->
parent
->
getKey
();
return
$this
->
parent
->
getKey
();
}
}
/**
* Return update values
*
* @param $array
* @param string $prepend
* @return array
*/
public
static
function
getUpdateValues
(
$array
,
$prepend
=
''
)
{
$results
=
[];
foreach
(
$array
as
$key
=>
$value
)
{
$results
[
$prepend
.
$key
]
=
$value
;
}
return
$results
;
}
}
}
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