File tree 2 files changed +21
-1
lines changed
src/Illuminate/Database/Eloquent/Concerns
tests/Integration/Database
2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -1086,7 +1086,11 @@ public function relationLoaded($key)
1086
1086
}
1087
1087
1088
1088
if ($ nestedRelation !== null ) {
1089
- foreach ($ this ->$ relation as $ related ) {
1089
+ $ relatedModels = is_iterable ($ relatedModels = $ this ->$ relation )
1090
+ ? $ relatedModels
1091
+ : [$ relatedModels ];
1092
+
1093
+ foreach ($ relatedModels as $ related ) {
1090
1094
if (! $ related ->relationLoaded ($ nestedRelation )) {
1091
1095
return false ;
1092
1096
}
Original file line number Diff line number Diff line change @@ -119,6 +119,22 @@ public function testWhenChildRecursiveRelationIsLoaded()
119
119
$ this ->assertTrue ($ model ->relationLoaded ('twos.threes ' ));
120
120
$ this ->assertTrue ($ model ->relationLoaded ('twos.threes.one ' ));
121
121
}
122
+
123
+ public function testWhenParentRelationIsASingleInstance ()
124
+ {
125
+ $ one = One::query ()->create ();
126
+ $ two = $ one ->twos ()->create ();
127
+ $ three = $ two ->threes ()->create ();
128
+
129
+ $ model = Three::query ()
130
+ ->with ('two.one ' )
131
+ ->find ($ three ->id );
132
+
133
+ $ this ->assertTrue ($ model ->relationLoaded ('two ' ));
134
+ $ this ->assertTrue ($ model ->two ->is ($ two ));
135
+ $ this ->assertTrue ($ model ->relationLoaded ('two.one ' ));
136
+ $ this ->assertTrue ($ model ->two ->one ->is ($ one ));
137
+ }
122
138
}
123
139
124
140
class One extends Model
You can’t perform that action at this time.
0 commit comments