Offset issue resolved for scanning results back into struct
This commit is contained in:
		
							parent
							
								
									38a24606da
								
							
						
					
					
						commit
						26a80b0993
					
				
							
								
								
									
										2
									
								
								scan.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								scan.go
									
									
									
									
									
								
							@ -196,7 +196,7 @@ func Scan(rows Rows, db *DB, mode ScanMode) {
 | 
				
			|||||||
				for idx, column := range columns {
 | 
									for idx, column := range columns {
 | 
				
			||||||
					if field := sch.LookUpField(column); field != nil && field.Readable {
 | 
										if field := sch.LookUpField(column); field != nil && field.Readable {
 | 
				
			||||||
						if curIndex, ok := selectedColumnsMap[column]; ok {
 | 
											if curIndex, ok := selectedColumnsMap[column]; ok {
 | 
				
			||||||
							for fieldIndex, selectField := range sch.Fields[curIndex:] {
 | 
												for fieldIndex, selectField := range sch.Fields[curIndex+1:] {
 | 
				
			||||||
								if selectField.DBName == column && selectField.Readable {
 | 
													if selectField.DBName == column && selectField.Readable {
 | 
				
			||||||
									selectedColumnsMap[column] = curIndex + fieldIndex + 1
 | 
														selectedColumnsMap[column] = curIndex + fieldIndex + 1
 | 
				
			||||||
									fields[idx] = selectField
 | 
														fields[idx] = selectField
 | 
				
			||||||
 | 
				
			|||||||
@ -184,11 +184,34 @@ func TestScanToEmbedded(t *testing.T) {
 | 
				
			|||||||
		t.Errorf("Failed to run join query, got error: %v", err)
 | 
							t.Errorf("Failed to run join query, got error: %v", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						personMatched := false
 | 
				
			||||||
 | 
						addressMatched := false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, info := range personAddressInfoList {
 | 
						for _, info := range personAddressInfoList {
 | 
				
			||||||
		if info.Person != nil {
 | 
							if info.Person == nil {
 | 
				
			||||||
			if info.Person.ID == person1.ID && info.Person.Name != person1.Name {
 | 
								t.Fatalf("Failed, expected not nil, got person nil")
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if info.Address == nil {
 | 
				
			||||||
 | 
								t.Fatalf("Failed, expected not nil, got address nil")
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if info.Person.ID == person1.ID {
 | 
				
			||||||
 | 
								personMatched = true
 | 
				
			||||||
 | 
								if info.Person.Name != person1.Name {
 | 
				
			||||||
				t.Errorf("Failed, expected %v, got %v", person1.Name, info.Person.Name)
 | 
									t.Errorf("Failed, expected %v, got %v", person1.Name, info.Person.Name)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							if info.Address.ID == address1.ID {
 | 
				
			||||||
 | 
								addressMatched = true
 | 
				
			||||||
 | 
								if info.Address.Name != address1.Name {
 | 
				
			||||||
 | 
									t.Errorf("Failed, expected %v, got %v", address1.Name, info.Address.Name)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !personMatched {
 | 
				
			||||||
 | 
							t.Errorf("Failed, no person matched")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if !addressMatched {
 | 
				
			||||||
 | 
							t.Errorf("Failed, no address matched")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user