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:
Femaref 2015-04-26 16:34:52 +02:00
parent 3c2915a9df
commit fa696b0e2f
1 changed files with 1 additions and 1 deletions

View File

@ -18,7 +18,7 @@ func Query(scope *Scope) {
if orderBy, ok := scope.Get("gorm:order_by_primary_key"); ok { if orderBy, ok := scope.Get("gorm:order_by_primary_key"); ok {
if primaryKey := scope.PrimaryKey(); primaryKey != "" { 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))
} }
} }