should check inner condition length (#7512)
This commit is contained in:
		
							parent
							
								
									991c2d4891
								
							
						
					
					
						commit
						985940f0d8
					
				| @ -341,7 +341,9 @@ func (stmt *Statement) BuildCondition(query interface{}, args ...interface{}) [] | ||||
| 				if where, ok := cs.Expression.(clause.Where); ok { | ||||
| 					if len(where.Exprs) == 1 { | ||||
| 						if orConds, ok := where.Exprs[0].(clause.OrConditions); ok { | ||||
| 							where.Exprs[0] = clause.AndConditions(orConds) | ||||
| 							if len(orConds.Exprs) == 1 { | ||||
| 								where.Exprs[0] = clause.AndConditions(orConds) | ||||
| 							} | ||||
| 						} | ||||
| 					} | ||||
| 					conds = append(conds, clause.And(where.Exprs...)) | ||||
|  | ||||
| @ -632,6 +632,21 @@ func TestOr(t *testing.T) { | ||||
| 		t.Fatalf("Build OR condition, but got %v", result.Statement.SQL.String()) | ||||
| 	} | ||||
| 
 | ||||
| 	sub := dryDB.Clauses(clause.Where{ | ||||
| 		Exprs: []clause.Expression{ | ||||
| 			clause.OrConditions{ | ||||
| 				Exprs: []clause.Expression{ | ||||
| 					clause.Expr{SQL: "role = ?", Vars: []interface{}{"super_admin"}}, | ||||
| 					clause.Expr{SQL: "role = ?", Vars: []interface{}{"admin"}}, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 	}) | ||||
| 	result = dryDB.Where(sub).Find(&User{}) | ||||
| 	if !regexp.MustCompile("SELECT \\* FROM .*users.* WHERE .*role.* = .+ OR .*role.* = .+").MatchString(result.Statement.SQL.String()) { | ||||
| 		t.Fatalf("Build OR condition, but got %v", result.Statement.SQL.String()) | ||||
| 	} | ||||
| 
 | ||||
| 	result = dryDB.Where("role = ?", "admin").Or("role = ?", "super_admin").Find(&User{}) | ||||
| 	if !regexp.MustCompile("SELECT \\* FROM .*users.* WHERE .*role.* = .+ OR .*role.* = .+").MatchString(result.Statement.SQL.String()) { | ||||
| 		t.Fatalf("Build OR condition, but got %v", result.Statement.SQL.String()) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Riseif
						Riseif