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

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

Closed
LaravelFreelancerNL opened this issue Aug 25, 2024 · 0 comments · Fixed by #160
Closed

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

LaravelFreelancerNL opened this issue Aug 25, 2024 · 0 comments · Fixed by #160

Comments

@LaravelFreelancerNL
Copy link
Owner

LaravelFreelancerNL commented Aug 25, 2024

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.

@LaravelFreelancerNL LaravelFreelancerNL changed the title Collection of model objectss doesn't eager load relationships Collection of model objects doesn't eager load relationships Aug 25, 2024
@LaravelFreelancerNL LaravelFreelancerNL linked a pull request Aug 25, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant