Fix order by primary key if it is not defined

This commit is contained in:
Jinzhu 2020-06-02 11:30:21 +08:00
parent 64ed645e4d
commit 669ce48f19
1 changed files with 2 additions and 0 deletions

View File

@ -90,6 +90,8 @@ func (stmt Statement) QuoteTo(writer clause.Writer, field interface{}) {
if v.Name == clause.PrimaryKey {
if stmt.Schema != nil && stmt.Schema.PrioritizedPrimaryField != nil {
stmt.DB.Dialector.QuoteTo(writer, stmt.Schema.PrioritizedPrimaryField.DBName)
} else if len(stmt.Schema.DBNames) > 0 {
stmt.DB.Dialector.QuoteTo(writer, stmt.Schema.DBNames[0])
}
} else if v.Raw {
writer.WriteString(v.Name)