Skip to content

Commit 5548f95

Browse files
authored
[12.x] Fix for global automaticallyEagerLoadRelationships not working in certain cases (#55443)
1 parent e7ad734 commit 5548f95

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/Illuminate/Database/Eloquent/Builder.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -854,13 +854,9 @@ public function get($columns = ['*'])
854854
$models = $builder->eagerLoadRelations($models);
855855
}
856856

857-
$collection = $builder->getModel()->newCollection($models);
858-
859-
if (Model::isAutomaticallyEagerLoadingRelationships()) {
860-
$collection->withRelationshipAutoloading();
861-
}
862-
863-
return $this->applyAfterQueryCallbacks($collection);
857+
return $this->applyAfterQueryCallbacks(
858+
$builder->getModel()->newCollection($models)
859+
);
864860
}
865861

866862
/**

src/Illuminate/Database/Eloquent/HasCollection.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ public function newCollection(array $models = [])
2727
{
2828
static::$resolvedCollectionClasses[static::class] ??= ($this->resolveCollectionFromAttribute() ?? static::$collectionClass);
2929

30-
return new static::$resolvedCollectionClasses[static::class]($models);
30+
$collection = new static::$resolvedCollectionClasses[static::class]($models);
31+
32+
if (Model::isAutomaticallyEagerLoadingRelationships()) {
33+
$collection->withRelationshipAutoloading();
34+
}
35+
36+
return $collection;
3137
}
3238

3339
/**

0 commit comments

Comments
 (0)
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