Do not always override select on pluck
This commit is contained in:
		
							parent
							
								
									c3bb6aaa82
								
							
						
					
					
						commit
						39a4402472
					
				
							
								
								
									
										18
									
								
								scope.go
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								scope.go
									
									
									
									
									
								
							@ -924,14 +924,30 @@ func (scope *Scope) initialize() *Scope {
 | 
			
		||||
	return scope
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (scope *Scope) isQueryForColumn(query interface{}, column string) bool {
 | 
			
		||||
	queryStr := fmt.Sprint(query)
 | 
			
		||||
	if queryStr == column {
 | 
			
		||||
		return true
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if strings.HasSuffix(strings.ToLower(queryStr), "as "+column) {
 | 
			
		||||
		return true
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return false
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (scope *Scope) pluck(column string, value interface{}) *Scope {
 | 
			
		||||
	dest := reflect.Indirect(reflect.ValueOf(value))
 | 
			
		||||
	scope.Search.Select(column)
 | 
			
		||||
	if dest.Kind() != reflect.Slice {
 | 
			
		||||
		scope.Err(fmt.Errorf("results should be a slice, not %s", dest.Kind()))
 | 
			
		||||
		return scope
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if query, ok := scope.Search.selects["query"]; !ok || !scope.isQueryForColumn(query, column) {
 | 
			
		||||
		scope.Search.Select(column)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	rows, err := scope.rows()
 | 
			
		||||
	if scope.Err(err) == nil {
 | 
			
		||||
		defer rows.Close()
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user