@@ -41,6 +41,13 @@ public function setModel($model): self
4141 return $ this ;
4242 }
4343
44+ protected function shouldShowRelationFor (string $ column ): bool
45+ {
46+ $ columns = Str::trimSplit ($ column , '. ' );
47+
48+ return $ columns [0 ] !== $ this ->model ->getTableName ();
49+ }
50+
4451 protected function createQuickSearchFilter ($ searchTerm )
4552 {
4653 $ model = $ this ->model ;
@@ -161,15 +168,21 @@ protected static function collectRelations(Resolver $resolver, Model $subject, a
161168 foreach ($ resolver ->getRelations ($ subject ) as $ name => $ relation ) {
162169 /** @var Relation $relation */
163170 $ isHasOne = $ relation instanceof HasOne;
164- if (empty ($ path )) {
165- $ relationPath = [$ name ];
166- if ($ isHasOne && empty ($ path )) {
171+ $ relationPath = [$ name ];
172+
173+ if (! isset ($ models [$ name ]) && ! in_array ($ name , $ path , true )) {
174+ if ($ isHasOne ) {
167175 array_unshift ($ relationPath , $ subject ->getTableName ());
168176 }
169177
170178 $ relationPath = array_merge ($ path , $ relationPath );
171- $ models [join ('. ' , $ relationPath )] = $ relation ->getTarget ();
172- self ::collectRelations ($ resolver , $ relation ->getTarget (), $ models , $ relationPath );
179+ $ targetPath = join ('. ' , $ relationPath );
180+
181+ if (! isset ($ models [$ targetPath ])) {
182+ $ models [$ targetPath ] = $ relation ->getTarget ();
183+ self ::collectRelations ($ resolver , $ relation ->getTarget (), $ models , $ relationPath );
184+ return ;
185+ }
173186 }
174187 }
175188 }
0 commit comments