From a56aa164739ae3449635e831af39ee852f5764b3 Mon Sep 17 00:00:00 2001 From: Mayank Govilla Date: Thu, 4 Nov 2021 20:15:21 -0400 Subject: [PATCH] add relation equality check to avoid skipping self-referential schemas --- schema/relationship.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schema/relationship.go b/schema/relationship.go index 5699ec5f..c5d3dcad 100644 --- a/schema/relationship.go +++ b/schema/relationship.go @@ -519,7 +519,7 @@ func (rel *Relationship) ParseConstraint() *Constraint { if rel.Type == BelongsTo { for _, r := range rel.FieldSchema.Relationships.Relations { - if r.FieldSchema == rel.Schema && len(rel.References) == len(r.References) { + if r != rel && r.FieldSchema == rel.Schema && len(rel.References) == len(r.References) { matched := true for idx, ref := range r.References { if !(rel.References[idx].PrimaryKey == ref.PrimaryKey && rel.References[idx].ForeignKey == ref.ForeignKey &&