diff --git a/schema/relationship.go b/schema/relationship.go index 1aa2d11a..606e722a 100644 --- a/schema/relationship.go +++ b/schema/relationship.go @@ -512,6 +512,24 @@ func (rel *Relationship) ParseConstraint() *Constraint { return nil } + if rel.Type == BelongsTo { + for _, r := range rel.FieldSchema.Relationships.Relations { + if 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 && + rel.References[idx].PrimaryValue == ref.PrimaryValue) { + matched = false + } + } + + if matched { + return nil + } + } + } + } + var ( name string idx = strings.Index(str, ",")