Skip to content

Allow to sync a single model instance #2396

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Relations/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Database\Eloquent\Model as EloquentModel;
use Illuminate\Database\Eloquent\Relations\BelongsToMany as EloquentBelongsToMany;
use Illuminate\Support\Arr;
use Jenssegers\Mongodb\Eloquent\Model as MongodbModel;

class BelongsToMany extends EloquentBelongsToMany
{
Expand Down Expand Up @@ -122,7 +123,9 @@ public function sync($ids, $detaching = true)

if ($ids instanceof Collection) {
$ids = $ids->modelKeys();
}
} elseif ($ids instanceof MongodbModel) {
$ids = [$ids->{$this->relatedKey}];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for not using InteractsWithPivotTable::parseIds as in the parent class?

}

// First we need to attach any of the associated models that are not currently
// in this joining table. We'll spin through the given IDs, checking to see
Expand Down