laravel-mongodb icon indicating copy to clipboard operation
laravel-mongodb copied to clipboard

withTrashed in MorphTo relation

Open RomM1 opened this issue 6 years ago • 0 comments

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();
}

RomM1 avatar Nov 07 '17 13:11 RomM1