mirror of https://github.com/go-gorm/gorm.git
Simpler (and correct) example for showing how to declare foreign keys.
Impact: Trivial.
This commit is contained in:
parent
3c2915a9df
commit
a9aef2dd90
|
@ -1091,7 +1091,7 @@ type Product struct {
|
|||
// 2nd param : destination table(id)
|
||||
// 3rd param : ONDELETE
|
||||
// 4th param : ONUPDATE
|
||||
db.Model(&User{}).AddForeignKey("user_id", "destination_table(id)", "CASCADE", "RESTRICT")
|
||||
db.Model(&User{}).AddForeignKey("role_id", "roles", "CASCADE", "RESTRICT")
|
||||
|
||||
// Add index
|
||||
db.Model(&User{}).AddIndex("idx_user_name", "name")
|
||||
|
|
Loading…
Reference in New Issue