fix maybe nil panic
This commit is contained in:
parent
328f301982
commit
e19dac065e
@ -160,7 +160,8 @@ func (schema *Schema) buildPolymorphicRelation(relation *Relationship, field *Fi
|
||||
|
||||
primaryKeyField := schema.PrioritizedPrimaryField
|
||||
if len(relation.foreignKeys) > 0 {
|
||||
if primaryKeyField = schema.LookUpField(relation.foreignKeys[0]); primaryKeyField == nil || len(relation.foreignKeys) > 1 {
|
||||
primaryKeyField = schema.LookUpField(relation.foreignKeys[0])
|
||||
if primaryKeyField == nil || len(relation.foreignKeys) > 1 {
|
||||
schema.err = fmt.Errorf("invalid polymorphic foreign keys %+v for %v on field %s", relation.foreignKeys, schema, field.Name)
|
||||
}
|
||||
}
|
||||
|
@ -113,6 +113,9 @@ func TestCallbacks(t *testing.T) {
|
||||
|
||||
for idx, data := range datas {
|
||||
db, err := gorm.Open(nil, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
callbacks := db.Callback()
|
||||
|
||||
for _, c := range data.callbacks {
|
||||
|
@ -102,7 +102,7 @@ func TestTransactionWithBlock(t *testing.T) {
|
||||
return errors.New("the error message")
|
||||
})
|
||||
|
||||
if err.Error() != "the error message" {
|
||||
if err != nil && err.Error() != "the error message" {
|
||||
t.Fatalf("Transaction return error will equal the block returns error")
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user