laravel-mongodb
laravel-mongodb copied to clipboard
withTrashed in MorphTo relation
Hello. I have a problem with withTrashed in MorphTo relation. (Embed model) withTrashed not disable the global scope, and I cannot get the deleted records. I have a workaround, tell me if there is a better way.
To replace it (jenssegers/mongodb/src/Jenssegers/Mongodb/Relations/MorphTo.php)
protected function getResultsByType($type)
{
$instance = $this->createModelByType($type);
$key = $instance->getKeyName();
$query = $instance->newQuery();
return $query->whereIn($key, $this->gatherKeysByType($type))->get();
}
On
protected function getResultsByType($type)
{
$instance = $this->createModelByType($type);
$key = $instance->getKeyName();
$query = $this->replayMacros($instance->newQuery())
->mergeConstraintsFrom($this->getQuery())
->with($this->getQuery()->getEagerLoads());
return $query->whereIn($key, $this->gatherKeysByType($type))->get();
}