forked from mirror/gorm
Fix create duplicated constraint, close #4090
This commit is contained in:
parent
628a0ae707
commit
92a2389450
|
@ -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, ",")
|
||||
|
|
Loading…
Reference in New Issue