diff --git a/documents/associations.md b/documents/associations.md index bba6234e..595f1fef 100644 --- a/documents/associations.md +++ b/documents/associations.md @@ -6,17 +6,17 @@ ```go // `User` belongs to `Profile`, `ProfileID` is the foreign key +type Profile struct { + gorm.Model + Name string +} + type User struct { gorm.Model Profile Profile ProfileID int } -type Profile struct { - gorm.Model - Name string -} - db.Model(&user).Related(&profile) //// SELECT * FROM profiles WHERE id = 111; // 111 is user's foreign key ProfileID ```