Skip to content

Package doesn't consider Model::automaticallyEagerLoadRelationships() and throws LazyLoadingViolationException #309

@decadence

Description

@decadence

I think this package doesn't consider Model::automaticallyEagerLoadRelationships().

This code throws LazyLoadingViolationException if Model::preventLazyLoading() is enabled:

Model::automaticallyEagerLoadRelationships();
Model::preventLazyLoading();

$services = Service::query()
            ->orderBy("name", "ASC")
            ->get();

foreach ($services as $service){
    $service->children;
}

But relationship should load automatically.

If I call withRelationshipAutoloading on Collection then it works normal:

Model::preventLazyLoading();

$services = Service::query()
            ->orderBy("name", "ASC")
            ->get()
            ->withRelationshipAutoloading();

foreach ($services as $service){
    $service->children;
}

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