Fix batch find
This commit is contained in:
		
							parent
							
								
									09b6fc3ab0
								
							
						
					
					
						commit
						97fc5878e9
					
				
							
								
								
									
										24
									
								
								orm_test.go
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								orm_test.go
									
									
									
									
									
								
							| @ -1,10 +1,15 @@ | ||||
| package gorm | ||||
| 
 | ||||
| import "testing" | ||||
| import ( | ||||
| 	"testing" | ||||
| 	"time" | ||||
| ) | ||||
| 
 | ||||
| type User struct { | ||||
| 	Id   int64 | ||||
| 	Name string | ||||
| 	Id       int64 | ||||
| 	Age      int64 | ||||
| 	Birthday time.Time | ||||
| 	Name     string | ||||
| } | ||||
| 
 | ||||
| var db DB | ||||
| @ -110,3 +115,16 @@ func TestWhere(t *testing.T) { | ||||
| 		t.Errorf("Shouldn't find anything when looking for none existing records, %+v", users) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func TestComplexWhere(t *testing.T) { | ||||
| 	db.Save(&User{Name: "1", Age: 18}) | ||||
| 	db.Save(&User{Name: "2", Age: 20}) | ||||
| 	db.Save(&User{Name: "3", Age: 22}) | ||||
| 	db.Save(&User{Name: "3", Age: 24}) | ||||
| 
 | ||||
| 	var users []User | ||||
| 	db.Where("age > ?", 20).Find(&users) | ||||
| 	if len(users) != 2 { | ||||
| 		t.Errorf("Should only have 2 users age great than 20, but have %v", len(users)) | ||||
| 	} | ||||
| } | ||||
|  | ||||
							
								
								
									
										5
									
								
								sql.go
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								sql.go
									
									
									
									
									
								
							| @ -65,7 +65,12 @@ func (s *Orm) query(out interface{}) { | ||||
| 			values = append(values, dest.FieldByName(snakeToUpperCamel(value)).Addr().Interface()) | ||||
| 		} | ||||
| 		s.Error = rows.Scan(values...) | ||||
| 
 | ||||
| 		if is_slice { | ||||
| 			dest_out.Set(reflect.Append(dest_out, dest)) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if (counts == 0) && !is_slice { | ||||
| 		s.Error = errors.New("Record not found!") | ||||
| 	} | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Jinzhu
						Jinzhu