add relation equality check to avoid skipping self-referential schemas

This commit is contained in:
Mayank Govilla 2021-11-04 20:15:21 -04:00
parent 8efabf38d1
commit a56aa16473

View File

@ -519,7 +519,7 @@ func (rel *Relationship) ParseConstraint() *Constraint {
if rel.Type == BelongsTo { if rel.Type == BelongsTo {
for _, r := range rel.FieldSchema.Relationships.Relations { 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 matched := true
for idx, ref := range r.References { for idx, ref := range r.References {
if !(rel.References[idx].PrimaryKey == ref.PrimaryKey && rel.References[idx].ForeignKey == ref.ForeignKey && if !(rel.References[idx].PrimaryKey == ref.PrimaryKey && rel.References[idx].ForeignKey == ref.ForeignKey &&