mirror of https://github.com/go-gorm/gorm.git
Fix create join table
This commit is contained in:
parent
d02c2a37ea
commit
4786e830d6
|
@ -71,7 +71,7 @@ type StructField struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (structField *StructField) clone() *StructField {
|
func (structField *StructField) clone() *StructField {
|
||||||
return &StructField{
|
clone := &StructField{
|
||||||
DBName: structField.DBName,
|
DBName: structField.DBName,
|
||||||
Name: structField.Name,
|
Name: structField.Name,
|
||||||
Names: structField.Names,
|
Names: structField.Names,
|
||||||
|
@ -81,11 +81,17 @@ func (structField *StructField) clone() *StructField {
|
||||||
IsScanner: structField.IsScanner,
|
IsScanner: structField.IsScanner,
|
||||||
HasDefaultValue: structField.HasDefaultValue,
|
HasDefaultValue: structField.HasDefaultValue,
|
||||||
Tag: structField.Tag,
|
Tag: structField.Tag,
|
||||||
TagSettings: structField.TagSettings,
|
TagSettings: map[string]string{},
|
||||||
Struct: structField.Struct,
|
Struct: structField.Struct,
|
||||||
IsForeignKey: structField.IsForeignKey,
|
IsForeignKey: structField.IsForeignKey,
|
||||||
Relationship: structField.Relationship,
|
Relationship: structField.Relationship,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for key, value := range structField.TagSettings {
|
||||||
|
clone.TagSettings[key] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
return clone
|
||||||
}
|
}
|
||||||
|
|
||||||
// Relationship described the relationship between models
|
// Relationship described the relationship between models
|
||||||
|
|
2
scope.go
2
scope.go
|
@ -1027,6 +1027,7 @@ func (scope *Scope) createJoinTable(field *StructField) {
|
||||||
foreignKeyStruct := field.clone()
|
foreignKeyStruct := field.clone()
|
||||||
foreignKeyStruct.IsPrimaryKey = false
|
foreignKeyStruct.IsPrimaryKey = false
|
||||||
foreignKeyStruct.TagSettings["IS_JOINTABLE_FOREIGNKEY"] = "true"
|
foreignKeyStruct.TagSettings["IS_JOINTABLE_FOREIGNKEY"] = "true"
|
||||||
|
delete(foreignKeyStruct.TagSettings, "AUTO_INCREMENT")
|
||||||
sqlTypes = append(sqlTypes, scope.Quote(relationship.ForeignDBNames[idx])+" "+scope.Dialect().DataTypeOf(foreignKeyStruct))
|
sqlTypes = append(sqlTypes, scope.Quote(relationship.ForeignDBNames[idx])+" "+scope.Dialect().DataTypeOf(foreignKeyStruct))
|
||||||
primaryKeys = append(primaryKeys, scope.Quote(relationship.ForeignDBNames[idx]))
|
primaryKeys = append(primaryKeys, scope.Quote(relationship.ForeignDBNames[idx]))
|
||||||
}
|
}
|
||||||
|
@ -1037,6 +1038,7 @@ func (scope *Scope) createJoinTable(field *StructField) {
|
||||||
foreignKeyStruct := field.clone()
|
foreignKeyStruct := field.clone()
|
||||||
foreignKeyStruct.IsPrimaryKey = false
|
foreignKeyStruct.IsPrimaryKey = false
|
||||||
foreignKeyStruct.TagSettings["IS_JOINTABLE_FOREIGNKEY"] = "true"
|
foreignKeyStruct.TagSettings["IS_JOINTABLE_FOREIGNKEY"] = "true"
|
||||||
|
delete(foreignKeyStruct.TagSettings, "AUTO_INCREMENT")
|
||||||
sqlTypes = append(sqlTypes, scope.Quote(relationship.AssociationForeignDBNames[idx])+" "+scope.Dialect().DataTypeOf(foreignKeyStruct))
|
sqlTypes = append(sqlTypes, scope.Quote(relationship.AssociationForeignDBNames[idx])+" "+scope.Dialect().DataTypeOf(foreignKeyStruct))
|
||||||
primaryKeys = append(primaryKeys, scope.Quote(relationship.AssociationForeignDBNames[idx]))
|
primaryKeys = append(primaryKeys, scope.Quote(relationship.AssociationForeignDBNames[idx]))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue