Merge 3896f294fd0c1c575e5c85ee0784f41cb41e6b69 into 4c93473b2d05cc6a57be49f2a5713c087853088a
This commit is contained in:
commit
a8dd3c010a
19
scope.go
19
scope.go
@ -1129,6 +1129,25 @@ func (scope *Scope) createTable() *Scope {
|
||||
scope.createJoinTable(field)
|
||||
}
|
||||
|
||||
var uniqueConstraints = map[string][]string{}
|
||||
|
||||
for _, field := range scope.GetStructFields() {
|
||||
if name, ok := field.TagSettings["UNIQUE_CONSTRAINT"]; ok {
|
||||
names := strings.Split(name, ",")
|
||||
|
||||
for _, name := range names {
|
||||
if name == "UNIQUE_CONSTRAINT" || name == "" {
|
||||
name = fmt.Sprintf("uix_%v_%v", scope.TableName(), field.DBName)
|
||||
}
|
||||
uniqueConstraints[name] = append(uniqueConstraints[name], field.DBName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, columns := range uniqueConstraints {
|
||||
tags = append(tags, fmt.Sprintf("UNIQUE (%s)", strings.Join(columns, ",")))
|
||||
}
|
||||
|
||||
var primaryKeyStr string
|
||||
if len(primaryKeys) > 0 && !primaryKeyInColumnType {
|
||||
primaryKeyStr = fmt.Sprintf(", PRIMARY KEY (%v)", strings.Join(primaryKeys, ","))
|
||||
|
Loading…
x
Reference in New Issue
Block a user