File tree 3 files changed +20
-6
lines changed
src/Jenssegers/Mongodb/Relations
3 files changed +20
-6
lines changed Original file line number Diff line number Diff line change 6
6
use Illuminate \Database \Eloquent \Model ;
7
7
use Illuminate \Pagination \LengthAwarePaginator ;
8
8
use Illuminate \Pagination \Paginator ;
9
- use Illuminate \Support \Arr ;
10
9
use MongoDB \BSON \ObjectID ;
11
10
12
11
class EmbedsMany extends EmbedsOneOrMany
@@ -79,8 +78,7 @@ public function performUpdate(Model $model)
79
78
// Get the correct foreign key value.
80
79
$ foreignKey = $ this ->getForeignKeyValue ($ model );
81
80
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 . '.$. ' );
84
82
85
83
// Update document in database.
86
84
$ result = $ this ->getBaseQuery ()->where ($ this ->localKey . '. ' . $ model ->getKeyName (), $ foreignKey )
Original file line number Diff line number Diff line change 3
3
namespace Jenssegers \Mongodb \Relations ;
4
4
5
5
use Illuminate \Database \Eloquent \Model ;
6
- use Illuminate \Support \Arr ;
7
6
use MongoDB \BSON \ObjectID ;
8
7
9
8
class EmbedsOne extends EmbedsOneOrMany
@@ -71,8 +70,7 @@ public function performUpdate(Model $model)
71
70
return $ this ->parent ->save ();
72
71
}
73
72
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 . '. ' );
76
74
77
75
$ result = $ this ->getBaseQuery ()->update ($ values );
78
76
Original file line number Diff line number Diff line change @@ -375,4 +375,22 @@ protected function getParentKey()
375
375
{
376
376
return $ this ->parent ->getKey ();
377
377
}
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
+ }
378
396
}
You can’t perform that action at this time.
0 commit comments