forked from mirror/gorm
Quote the primary column name when doing queries
Postgresql requires certain column names to be quoted. When unquoted, all upper-case characters will be converted to lower-case, and column names like 'typeID' will result in a query on 'typeid'.
This commit is contained in:
parent
3c2915a9df
commit
fa696b0e2f
|
@ -18,7 +18,7 @@ func Query(scope *Scope) {
|
|||
|
||||
if orderBy, ok := scope.Get("gorm:order_by_primary_key"); ok {
|
||||
if primaryKey := scope.PrimaryKey(); primaryKey != "" {
|
||||
scope.Search.Order(fmt.Sprintf("%v.%v %v", scope.QuotedTableName(), primaryKey, orderBy))
|
||||
scope.Search.Order(fmt.Sprintf("%v.%v %v", scope.QuotedTableName(), scope.Quote(primaryKey), orderBy))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue