Merge pull request #468 from nicholasf/master

Simpler (and correct) example for showing how to declare foreign keys.
This commit is contained in:
Jinzhu 2015-05-02 10:44:26 +08:00
commit 25772352c2
1 changed files with 1 additions and 1 deletions

View File

@ -1091,7 +1091,7 @@ type Product struct {
// 2nd param : destination table(id) // 2nd param : destination table(id)
// 3rd param : ONDELETE // 3rd param : ONDELETE
// 4th param : ONUPDATE // 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 // Add index
db.Model(&User{}).AddIndex("idx_user_name", "name") db.Model(&User{}).AddIndex("idx_user_name", "name")