Merge 8545f588249455f922d415a699e0526c779a1639 into 27a442b5ecef401a3ba2325383a96a09b0a983d9
This commit is contained in:
commit
2dbafd7729
15
README.md
15
README.md
@ -1116,6 +1116,21 @@ type Product struct {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Composite Foreign Primary Integer Keys
|
||||||
|
|
||||||
|
```go
|
||||||
|
type ProductStore struct {
|
||||||
|
ProductID int64 `gorm:"primary_key;foreignkey"`
|
||||||
|
StoreID int64 `gorm:"primary_key;foreignkey"`
|
||||||
|
Quantity int
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
When you declare a gorm primary key as foreign, there is likely no good use case for also auto incrementing the field.
|
||||||
|
This disables the auto increment behavior when creating the table from gorm.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Database Indexes & Foreign Key
|
## Database Indexes & Foreign Key
|
||||||
|
|
||||||
```go
|
```go
|
||||||
|
@ -350,6 +350,10 @@ func (scope *Scope) generateSqlTag(field *StructField) string {
|
|||||||
autoIncrease = true
|
autoIncrease = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if field.IsPrimaryKey && field.IsForeignKey {
|
||||||
|
autoIncrease = false
|
||||||
|
}
|
||||||
|
|
||||||
sqlType = scope.Dialect().SqlTag(reflectValue, size, autoIncrease)
|
sqlType = scope.Dialect().SqlTag(reflectValue, size, autoIncrease)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user