Skip to content

Collection of model objects doesn't eager load relationships #159

Closed
@LaravelFreelancerNL

Description

@LaravelFreelancerNL

When opne object of a model is retrieved with a relationship, eager loading works fine.
However when multiple objects are retrieved the relationship collection is set, but empty.

    $location = Location::with('inhabitants')->find('winterfell');

vs

    $locations = Location::with('inhabitants')->get();

      #relations: array:1 [
        "inhabitants" => Illuminate\Database\Eloquent\Collection {#2940 ▼
          #items: []
          #escapeWhenCastingToString: false
        }
      ]

This happens with a HasMany relationship, but not BelongsTo. Other relationships need to be checked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions