laravel-mongodb
laravel-mongodb copied to clipboard
`syncWithoutDetaching()` isn't accepting a single model as an argument
- Laravel Version: 9.13.0
- Laravel-mongodb Version: 3.9.0
- PHP Version: 8.0.17
- Database Driver & Version: MongoDB PHP, v5.0.6
Description:
When passing a model instance to a syncWithoutDetaching() method, an exception is thrown.
This behaviour differs from cases with Laravel's Eloquent models, when a single model is accepted by this method.
Steps to reproduce
Let's use a User and a Post entity for this example
- Create a
Postmodel - Create a
Usermodel with a one-to-many relation toPostone - Store a record of a single user in DB (without any related posts)
- Store a record of a single post in DB
- Pick a post record from a previous step via
Postmodel - Try to assign this post to a user like this:
$user->posts()->syncWithoutDetaching($post);
Expected behaviour
An existing post record should be put in a relationship with a user record
Actual behaviour
An exception is thrown instead:
Jenssegers\Mongodb\Relations\BelongsToMany::formatSyncList(): Argument #1 ($records) must be of type array, App\Models\Representative given