File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
src/Illuminate/Database/Eloquent
tests/Integration/Database Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -351,10 +351,12 @@ public function hydrate(array $items)
351
351
{
352
352
$ instance = $ this ->newModelInstance ();
353
353
354
- return $ instance ->newCollection (array_map (function ($ item ) use ($ instance ) {
354
+ return $ instance ->newCollection (array_map (function ($ item ) use ($ items , $ instance ) {
355
355
$ model = $ instance ->newFromBuilder ($ item );
356
356
357
- $ model ->preventsLazyLoading = Model::preventsLazyLoading ();
357
+ if (count ($ items ) > 1 ) {
358
+ $ model ->preventsLazyLoading = Model::preventsLazyLoading ();
359
+ }
358
360
359
361
return $ model ;
360
362
}, $ items ));
Original file line number Diff line number Diff line change @@ -48,6 +48,15 @@ public function testStrictModeThrowsAnExceptionOnLazyLoading()
48
48
$ models [0 ]->modelTwos ;
49
49
}
50
50
51
+ public function testStrictModeDoesntThrowAnExceptionOnLazyLoadingWithSingleModel ()
52
+ {
53
+ EloquentStrictLoadingTestModel1::create ();
54
+
55
+ $ models = EloquentStrictLoadingTestModel1::get ();
56
+
57
+ $ this ->assertInstanceOf (Collection::class, $ models );
58
+ }
59
+
51
60
public function testStrictModeDoesntThrowAnExceptionOnAttributes ()
52
61
{
53
62
EloquentStrictLoadingTestModel1::create ();
@@ -85,6 +94,8 @@ public function testStrictModeDoesntThrowAnExceptionOnSingleModelLoading()
85
94
{
86
95
$ model = EloquentStrictLoadingTestModel1::create ();
87
96
97
+ $ model = EloquentStrictLoadingTestModel1::find ($ model ->id );
98
+
88
99
$ this ->assertInstanceOf (Collection::class, $ model ->modelTwos );
89
100
}
90
101
@@ -95,6 +106,7 @@ public function testStrictModeThrowsAnExceptionOnLazyLoadingInRelations()
95
106
96
107
$ model1 = EloquentStrictLoadingTestModel1::create ();
97
108
EloquentStrictLoadingTestModel2::create (['model_1_id ' => $ model1 ->id ]);
109
+ EloquentStrictLoadingTestModel2::create (['model_1_id ' => $ model1 ->id ]);
98
110
99
111
$ models = EloquentStrictLoadingTestModel1::with ('modelTwos ' )->get ();
100
112
You can’t perform that action at this time.
0 commit comments