diff --git a/tests/Integration/Database/EloquentStrictLoadingTest.php b/tests/Integration/Database/EloquentStrictLoadingTest.php index 6b0f0c28edb5..8342c68b8438 100644 --- a/tests/Integration/Database/EloquentStrictLoadingTest.php +++ b/tests/Integration/Database/EloquentStrictLoadingTest.php @@ -143,6 +143,21 @@ public function testStrictModeWithOverriddenHandlerOnLazyLoading() $models[0]->modelTwos; } + + public function testStrictModeDoesntThrowAnExceptionOnManuallyMadeModel() + { + $model1 = EloquentStrictLoadingTestModel1WithLocalPreventsLazyLoading::make(); + $model2 = EloquentStrictLoadingTestModel2::make(); + $model1->modelTwos->push($model2); + + $this->assertInstanceOf(Collection::class, $model1->modelTwos); + } + + public function testStrictModeDoesntThrowAnExceptionOnRecentlyCreatedModel() + { + $model1 = EloquentStrictLoadingTestModel1WithLocalPreventsLazyLoading::create(); + $this->assertInstanceOf(Collection::class, $model1->modelTwos); + } } class EloquentStrictLoadingTestModel1 extends Model @@ -174,6 +189,19 @@ protected function handleLazyLoadingViolation($key) } } +class EloquentStrictLoadingTestModel1WithLocalPreventsLazyLoading extends Model +{ + public $table = 'test_model1'; + public $timestamps = false; + public $preventsLazyLoading = true; + protected $guarded = []; + + public function modelTwos() + { + return $this->hasMany(EloquentStrictLoadingTestModel2::class, 'model_1_id'); + } +} + class EloquentStrictLoadingTestModel2 extends Model { public $table = 'test_model2';