Skip to content

Commit 79ea62d

Browse files
committed
do not use array dot notation for updating embedded models
1 parent 1bb259a commit 79ea62d

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/Jenssegers/Mongodb/Relations/EmbedsMany.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Illuminate\Database\Eloquent\Model;
77
use Illuminate\Pagination\LengthAwarePaginator;
88
use Illuminate\Pagination\Paginator;
9-
use Illuminate\Support\Arr;
109
use MongoDB\BSON\ObjectID;
1110

1211
class EmbedsMany extends EmbedsOneOrMany
@@ -79,8 +78,7 @@ public function performUpdate(Model $model)
7978
// Get the correct foreign key value.
8079
$foreignKey = $this->getForeignKeyValue($model);
8180

82-
// Use array dot notation for better update behavior.
83-
$values = Arr::dot($model->getDirty(), $this->localKey . '.$.');
81+
$values = $this->getUpdateValues($model->getDirty(), $this->localKey . '.$.');
8482

8583
// Update document in database.
8684
$result = $this->getBaseQuery()->where($this->localKey . '.' . $model->getKeyName(), $foreignKey)

src/Jenssegers/Mongodb/Relations/EmbedsOne.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Jenssegers\Mongodb\Relations;
44

55
use Illuminate\Database\Eloquent\Model;
6-
use Illuminate\Support\Arr;
76
use MongoDB\BSON\ObjectID;
87

98
class EmbedsOne extends EmbedsOneOrMany
@@ -71,8 +70,7 @@ public function performUpdate(Model $model)
7170
return $this->parent->save();
7271
}
7372

74-
// Use array dot notation for better update behavior.
75-
$values = Arr::dot($model->getDirty(), $this->localKey . '.');
73+
$values = $this->getUpdateValues($model->getDirty(), $this->localKey . '.');
7674

7775
$result = $this->getBaseQuery()->update($values);
7876

src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,4 +375,22 @@ protected function getParentKey()
375375
{
376376
return $this->parent->getKey();
377377
}
378+
379+
/**
380+
* Return update values
381+
*
382+
* @param $array
383+
* @param string $prepend
384+
* @return array
385+
*/
386+
public static function getUpdateValues($array, $prepend = '')
387+
{
388+
$results = [];
389+
390+
foreach ($array as $key => $value) {
391+
$results[$prepend.$key] = $value;
392+
}
393+
394+
return $results;
395+
}
378396
}

0 commit comments

Comments
 (0)