Skip to content

withTrashed in MorphTo relation #1361

Open
@RomM1

Description

@RomM1

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs investigationNeed investigation about bugs described in issuebugrelationsRelations between documents

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions