Skip to content

Model::automaticallyEagerLoadRelationships doesn't work for BelongsToMany #55438

@decadence

Description

@decadence

Laravel Version

12.9.0

PHP Version

8.3.8

Database Driver & Version

MySQL 8.4

Description

Global Model::automaticallyEagerLoadRelationships doesn't work for BelongsToMany because it has its own get method which does not take into account this functionality.

And if you use Model::preventLazyLoading you get LazyLoadingViolationException.

Steps To Reproduce

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

// contracts is BelongsToMany relation
$contracts = $project->contracts()->get();

foreach ($contracts as $contract) {
    // LazyLoadingViolationException here
    $contractors[] = $contract->contractor;
}

@litvinchuk

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy