This reverts commit 664755270ddba77cc669de814afca71ae5575fce.
This commit is contained in:
		
							parent
							
								
									294625759c
								
							
						
					
					
						commit
						d6c23586ae
					
				| @ -104,11 +104,6 @@ func BuildQuerySQL(db *gorm.DB) { | ||||
| 			} | ||||
| 
 | ||||
| 			joins := []clause.Join{} | ||||
| 
 | ||||
| 			if fromClause, ok := db.Statement.Clauses["FROM"].Expression.(clause.From); ok { | ||||
| 				joins = fromClause.Joins | ||||
| 			} | ||||
| 
 | ||||
| 			for _, join := range db.Statement.Joins { | ||||
| 				if db.Statement.Schema == nil { | ||||
| 					joins = append(joins, clause.Join{ | ||||
|  | ||||
| @ -6,7 +6,6 @@ import ( | ||||
| 	"testing" | ||||
| 
 | ||||
| 	"gorm.io/gorm" | ||||
| 	"gorm.io/gorm/clause" | ||||
| 	. "gorm.io/gorm/utils/tests" | ||||
| ) | ||||
| 
 | ||||
| @ -243,47 +242,3 @@ func TestCombineStringConditions(t *testing.T) { | ||||
| 		t.Fatalf("invalid sql generated, got %v", sql) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func TestFromWithJoins(t *testing.T) { | ||||
| 	var result User | ||||
| 
 | ||||
| 	newDB := DB.Session(&gorm.Session{NewDB: true, DryRun: true}).Table("users") | ||||
| 
 | ||||
| 	newDB.Clauses( | ||||
| 		clause.From{ | ||||
| 			Tables: []clause.Table{{Name: "users"}}, | ||||
| 			Joins: []clause.Join{ | ||||
| 				{ | ||||
| 					Table: clause.Table{Name: "companies", Raw: false}, | ||||
| 					ON: clause.Where{ | ||||
| 						Exprs: []clause.Expression{ | ||||
| 							clause.Eq{ | ||||
| 								Column: clause.Column{ | ||||
| 									Table: "users", | ||||
| 									Name:  "company_id", | ||||
| 								}, | ||||
| 								Value: clause.Column{ | ||||
| 									Table: "companies", | ||||
| 									Name:  "id", | ||||
| 								}, | ||||
| 							}, | ||||
| 						}, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 	) | ||||
| 
 | ||||
| 	newDB.Joins("inner join rgs on rgs.id = user.id") | ||||
| 
 | ||||
| 	stmt := newDB.First(&result).Statement | ||||
| 	str := stmt.SQL.String() | ||||
| 
 | ||||
| 	if !strings.Contains(str, "rgs.id = user.id") { | ||||
| 		t.Errorf("The second join condition is over written instead of combining") | ||||
| 	} | ||||
| 
 | ||||
| 	if !strings.Contains(str, "`users`.`company_id` = `companies`.`id`") && !strings.Contains(str, "\"users\".\"company_id\" = \"companies\".\"id\"") { | ||||
| 		t.Errorf("The first join condition is over written instead of combining") | ||||
| 	} | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Jinzhu
						Jinzhu