We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When we use a BelongsToMany relationship with objectIf in foreignKey, this one are incorrectly cast.
Create Planet model:
<?php declare(strict_types=1); namespace App\Models\Test; use MongoDB\Laravel\Eloquent\Model; use MongoDB\Laravel\Relations\BelongsToMany; class Planet extends Model { protected $connection = 'mwe_mongodb'; protected $collection = 'TestPlanet'; public function getIdAttribute($value = null) { return $value; } public function visitors(): BelongsToMany { return $this->belongsToMany(SpaceExplorer::class, null, 'planetId', 'visitorId'); } }
Create SpaceExplorerModel
<?php declare(strict_types=1); namespace App\Models\Test; use MongoDB\Laravel\Eloquent\Model; use MongoDB\Laravel\Relations\BelongsToMany; class SpaceExplorer extends Model { protected $connection = 'mwe_mongodb'; protected $collection = 'TestSpaceExplorer'; public function getIdAttribute($value = null) { return $value; } public function planetsVisited(): BelongsToMany { return $this->belongsToMany(Planet::class, null, 'visitorIds', 'planetIds'); } }
And attach planet to spaceExplorer:
<?php use App\Models\Test\Planet; use App\Models\Test\SpaceExplorer; $planetEarth = new Planet(); $planetEarth->name = 'Earth'; $planetEarth->save(); $planetJupiter = new Planet(); $planetJupiter->name = 'Jupiter'; $planetJupiter->save(); $explorerTanya = new SpaceExplorer(); $explorerTanya->name = 'Tanya Kirbuk'; $explorerTanya->save(); $explorerTanya->planetsVisited()->attach($planetEarth); $explorerTanya->planetsVisited()->attach($planetJupiter);
The expected result
{ "_id" : ObjectId("667e95f3759cbea7c80d1a24"), "name" : "Tanya Kirbuk", "updated_at" : ISODate("2024-06-28T10:52:35.735+0000"), "created_at" : ISODate("2024-06-28T10:52:35.735+0000"), "planetIds" : [ ObjectId("667e95f3759cbea7c80d1a22"), ObjectId("667e95f3759cbea7c80d1a23") ] }
The current result
{ "_id" : ObjectId("667e967908ccc87ad000a294"), "name" : "Tanya Kirbuk", "updated_at" : ISODate("2024-06-28T10:54:49.690+0000"), "created_at" : ISODate("2024-06-28T10:54:49.690+0000"), "planetIds" : [ { "oid" : "667e967908ccc87ad000a292" }, { "oid" : "667e967908ccc87ad000a293" } ] }
I created a Pull request to resolve the issue #3014
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Description:
When we use a BelongsToMany relationship with objectIf in foreignKey, this one are incorrectly cast.
Create Planet model:
Create SpaceExplorerModel
And attach planet to spaceExplorer:
Expected behaviour
The expected result
Actual behaviour
The current result
I created a Pull request to resolve the issue #3014
The text was updated successfully, but these errors were encountered: