File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -377,10 +377,11 @@ protected function performJoinForEloquentPowerJoinsForHasManyThrough()
377377                    $ joinas ($ alias1
378378                }
379379
380+                 $ farParentTablegetTableOrAliasForModel ($ this getFarParent ());
380381                $ joinon (
381382                    "{$ throughTable. {$ this getFirstKeyName ()}" ,
382383                    '= ' ,
383-                     $ this getQualifiedLocalKeyName () 
384+                     "{ $ farParentTable } . { $ this localKey }" 
384385                );
385386
386387                if  ($ disableExtraConditionsfalse  && $ this usesSoftDeletes ($ this getThroughParent ())) {
Original file line number Diff line number Diff line change @@ -351,4 +351,35 @@ public function test_join_through_model_with_soft_deletes_using_alias()
351351            $ query
352352        );
353353    }
354+ 
355+     public  function  test_join_through_model_twice_using_alias ()
356+     {
357+         // has many throuh 
358+         $ queryjoinRelationship ('user.commentsThroughPosts ' , [
359+             'user '  => fn  ($ join$ joinas ('users_alias ' )->withTrashed (),
360+             'commentsThroughPosts '  => [
361+                 'posts '  => fn  ($ join$ joinas ('posts_alias ' )->withTrashed (),
362+             ],
363+         ])->toSql ();
364+ 
365+         // Expect users_alias.id to be used as the join key 
366+         $ this assertQueryContains (
367+             'inner join "posts" as "posts_alias" on "posts_alias"."user_id" = "users_alias"."id" ' ,
368+             $ query
369+         );
370+ 
371+         // has one through 
372+         $ queryjoinRelationship ('comments.postCategory ' , [
373+             'comments '  => fn  ($ join$ joinas ('comments_alias ' )->withTrashed (),
374+             'postCategory '  => [
375+                 'posts '  => fn  ($ join$ joinas ('posts_alias ' )->withTrashed (),
376+             ],
377+         ])->toSql ();
378+ 
379+         // Expect comments_alias.post_id to be used as the join key 
380+         $ this assertQueryContains (
381+             'inner join "posts" as "posts_alias" on "posts_alias"."id" = "comments_alias"."post_id" ' ,
382+             $ query
383+         );
384+     }
354385}
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments