forked from mirror/gorm
Fix panic when using Select/Omit Associations with no schema, close #3160
This commit is contained in:
parent
6dc583869b
commit
e77156980c
|
@ -503,7 +503,7 @@ func (stmt *Statement) SelectAndOmitColumns(requireCreate, requireUpdate bool) (
|
||||||
for _, dbName := range stmt.Schema.DBNames {
|
for _, dbName := range stmt.Schema.DBNames {
|
||||||
results[dbName] = true
|
results[dbName] = true
|
||||||
}
|
}
|
||||||
} else if column == clause.Associations {
|
} else if column == clause.Associations && stmt.Schema != nil {
|
||||||
for _, rel := range stmt.Schema.Relationships.Relations {
|
for _, rel := range stmt.Schema.Relationships.Relations {
|
||||||
results[rel.Name] = true
|
results[rel.Name] = true
|
||||||
}
|
}
|
||||||
|
@ -517,9 +517,11 @@ func (stmt *Statement) SelectAndOmitColumns(requireCreate, requireUpdate bool) (
|
||||||
// omit columns
|
// omit columns
|
||||||
for _, omit := range stmt.Omits {
|
for _, omit := range stmt.Omits {
|
||||||
if omit == clause.Associations {
|
if omit == clause.Associations {
|
||||||
|
if stmt.Schema != nil {
|
||||||
for _, rel := range stmt.Schema.Relationships.Relations {
|
for _, rel := range stmt.Schema.Relationships.Relations {
|
||||||
results[rel.Name] = false
|
results[rel.Name] = false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if field := stmt.Schema.LookUpField(omit); field != nil && field.DBName != "" {
|
} else if field := stmt.Schema.LookUpField(omit); field != nil && field.DBName != "" {
|
||||||
results[field.DBName] = false
|
results[field.DBName] = false
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue