forked from mirror/gorm
Fix Omit/Select without Model value, close #4098
This commit is contained in:
parent
73d44a4f97
commit
79225bfe48
16
statement.go
16
statement.go
|
@ -600,12 +600,14 @@ func (stmt *Statement) SelectAndOmitColumns(requireCreate, requireUpdate bool) (
|
||||||
|
|
||||||
// select columns
|
// select columns
|
||||||
for _, column := range stmt.Selects {
|
for _, column := range stmt.Selects {
|
||||||
if column == "*" {
|
if stmt.Schema == nil {
|
||||||
|
results[column] = true
|
||||||
|
} else if column == "*" {
|
||||||
notRestricted = true
|
notRestricted = true
|
||||||
for _, dbName := range stmt.Schema.DBNames {
|
for _, dbName := range stmt.Schema.DBNames {
|
||||||
results[dbName] = true
|
results[dbName] = true
|
||||||
}
|
}
|
||||||
} else if column == clause.Associations && stmt.Schema != nil {
|
} else if column == clause.Associations {
|
||||||
for _, rel := range stmt.Schema.Relationships.Relations {
|
for _, rel := range stmt.Schema.Relationships.Relations {
|
||||||
results[rel.Name] = true
|
results[rel.Name] = true
|
||||||
}
|
}
|
||||||
|
@ -618,11 +620,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 stmt.Schema == nil {
|
||||||
if stmt.Schema != nil {
|
results[omit] = false
|
||||||
for _, rel := range stmt.Schema.Relationships.Relations {
|
} else if omit == clause.Associations {
|
||||||
results[rel.Name] = false
|
for _, rel := range stmt.Schema.Relationships.Relations {
|
||||||
}
|
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
|
||||||
|
|
Loading…
Reference in New Issue