Skip to content

Eager loading MorphTo relationships with withTrashed() doesn't include soft-deleted models #3454

@StevePorter92

Description

@StevePorter92
  • Laravel-mongodb Version: 5.x
  • PHP Version: 8.x
  • Database Driver & Version: 1.2/2.0

Description:

Eager loading morphTo() relationships with withTrashed() does not include soft-deleted models. The MorphTo::getResultsByType() method in the MongoDB implementation doesn't replay macros (including withTrashed()), causing soft-deleted related models to be excluded from eager-loaded results.

Steps to reproduce

  1. See the test here test: Add test case for morph to soft delete functionality StevePorter92/laravel-mongodb#1
  2. Run the tets

Expected behaviour

The eager-loaded morphToSoftWithTrashed relationship should return the soft-deleted Soft model instance, matching Laravel's standard Eloquent behavior.

Actual behaviour

The eager-loaded relationship returns null instead of the soft-deleted model.

Potentially a duplicate of #1361, but the fix does not work

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions