Skip to content
New issue

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

withTrashed in MorphTo relation #1361

Open
RomM1 opened this issue Nov 7, 2017 · 0 comments
Open

withTrashed in MorphTo relation #1361

RomM1 opened this issue Nov 7, 2017 · 0 comments
Labels
bug Needs investigation Need investigation about bugs described in issue relations Relations between documents

Comments

@RomM1
Copy link
Contributor

RomM1 commented Nov 7, 2017

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();
}
@divine divine added bug Needs investigation Need investigation about bugs described in issue labels Feb 19, 2020
@GromNaN GromNaN added the relations Relations between documents label Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Needs investigation Need investigation about bugs described in issue relations Relations between documents
Projects
None yet
Development

No branches or pull requests

3 participants