Open florianJacques opened 7 months ago
I propose this solution to get around the problem without breaking the existing system. What do you think?
protected bool $castKey = true;
public function getIdAttribute($value = null): mixed
{
return $this->castKey ? parent::getIdAttribute($value) : $value;
}
public function accessTokens(): HasMany
{
$this->castKey = false;
$hasMany = $this->hasMany(AccessToken::class, 'userId', '_id');
$this->castKey = true;
return $hasMany;
}
Unfortunately does not work with method....
I don't know why you put a default attribute mutator on the id, I wonder if it shouldn't be removed.
https://github.com/mongodb/laravel-mongodb/issues/2753#issuecomment-2016523397
I have a simple replication for this issue
Hello The _id autocast is a problem on HasOne and HasMany relations, as it prevents comparisons with ObjectId
Indeed, this relationship always returns me null
But if I remove the line
The relation working