|
15 | 15 | use function array_map;
|
16 | 16 | use function array_merge;
|
17 | 17 | use function array_values;
|
| 18 | +use function assert; |
18 | 19 | use function count;
|
19 |
| -use function is_array; |
20 | 20 | use function is_numeric;
|
21 | 21 |
|
22 | 22 | class BelongsToMany extends EloquentBelongsToMany
|
@@ -82,11 +82,11 @@ protected function setWhere()
|
82 | 82 | }
|
83 | 83 |
|
84 | 84 | /** @inheritdoc */
|
85 |
| - public function save(Model $model, array $joining = [], $touch = true) |
| 85 | + public function save(Model $model, array $pivotAttributes = [], $touch = true) |
86 | 86 | {
|
87 | 87 | $model->save(['touch' => false]);
|
88 | 88 |
|
89 |
| - $this->attach($model, $joining, $touch); |
| 89 | + $this->attach($model, $pivotAttributes, $touch); |
90 | 90 |
|
91 | 91 | return $model;
|
92 | 92 | }
|
@@ -126,12 +126,7 @@ public function sync($ids, $detaching = true)
|
126 | 126 | // if they exist in the array of current ones, and if not we will insert.
|
127 | 127 | $current = $this->parent->{$this->relatedPivotKey} ?: [];
|
128 | 128 |
|
129 |
| - // See issue #256. |
130 |
| - if ($current instanceof Collection) { |
131 |
| - $current = $ids->modelKeys(); |
132 |
| - } |
133 |
| - |
134 |
| - $records = $this->formatSyncList($ids); |
| 129 | + $records = $this->formatRecordsList($ids); |
135 | 130 |
|
136 | 131 | $current = Arr::wrap($current);
|
137 | 132 |
|
@@ -171,6 +166,7 @@ public function sync($ids, $detaching = true)
|
171 | 166 | public function updateExistingPivot($id, array $attributes, $touch = true)
|
172 | 167 | {
|
173 | 168 | // Do nothing, we have no pivot table.
|
| 169 | + return $this; |
174 | 170 | }
|
175 | 171 |
|
176 | 172 | /** @inheritdoc */
|
@@ -229,6 +225,8 @@ public function detach($ids = [], $touch = true)
|
229 | 225 | }
|
230 | 226 |
|
231 | 227 | // Remove the relation to the parent.
|
| 228 | + assert($this->parent instanceof \MongoDB\Laravel\Eloquent\Model); |
| 229 | + assert($query instanceof \MongoDB\Laravel\Eloquent\Builder); |
232 | 230 | $query->pull($this->foreignPivotKey, $this->parent->getKey());
|
233 | 231 |
|
234 | 232 | if ($touch) {
|
@@ -266,7 +264,7 @@ public function newPivotQuery()
|
266 | 264 | /**
|
267 | 265 | * Create a new query builder for the related model.
|
268 | 266 | *
|
269 |
| - * @return \Illuminate\Database\Query\Builder |
| 267 | + * @return Builder|Model |
270 | 268 | */
|
271 | 269 | public function newRelatedQuery()
|
272 | 270 | {
|
@@ -295,28 +293,6 @@ public function getQualifiedRelatedPivotKeyName()
|
295 | 293 | return $this->relatedPivotKey;
|
296 | 294 | }
|
297 | 295 |
|
298 |
| - /** |
299 |
| - * Format the sync list so that it is keyed by ID. (Legacy Support) |
300 |
| - * The original function has been renamed to formatRecordsList since Laravel 5.3. |
301 |
| - * |
302 |
| - * @deprecated |
303 |
| - * |
304 |
| - * @return array |
305 |
| - */ |
306 |
| - protected function formatSyncList(array $records) |
307 |
| - { |
308 |
| - $results = []; |
309 |
| - foreach ($records as $id => $attributes) { |
310 |
| - if (! is_array($attributes)) { |
311 |
| - [$id, $attributes] = [$attributes, []]; |
312 |
| - } |
313 |
| - |
314 |
| - $results[$id] = $attributes; |
315 |
| - } |
316 |
| - |
317 |
| - return $results; |
318 |
| - } |
319 |
| - |
320 | 296 | /**
|
321 | 297 | * Get the name of the "where in" method for eager loading.
|
322 | 298 | *
|
|
0 commit comments