diff --git a/db/gorm.go b/db/gorm.go index bdbf3d1c..03c68936 100644 --- a/db/gorm.go +++ b/db/gorm.go @@ -30,7 +30,7 @@ func GormInit(conf *config.Config) (*gorm.DB, error) { // db.SingularTable(true) if config.Environment == "DEVELOPMENT" { db.LogMode(true) - db.AutoMigrate(&model.Torrents{}, &model.UsersFollowers{}, &model.User{}, &model.Comment{}, &model.OldComment{}) + db.AutoMigrate(&model.Torrents{}, &model.UserFollows{}, &model.User{}, &model.Comment{}, &model.OldComment{}) // db.Model(&model.User{}).AddIndex("idx_user_token", "token") } diff --git a/model/user.go b/model/user.go index 64455794..9bea5aa3 100644 --- a/model/user.go +++ b/model/user.go @@ -19,8 +19,8 @@ type User struct { // TODO: move this to PublicUser LikingCount int `json:"likingCount" gorm:"-"` LikedCount int `json:"likedCount" gorm:"-"` - Likings []User `gorm:"foreignkey:userId;associationforeignkey:follower_id;many2many:users_followers;"` - Liked []User `gorm:"foreignkey:follower_id;associationforeignkey:userId;many2many:users_followers;"` + Likings []User `gorm:"foreignkey:userId;associationforeignkey:follower_id;many2many:user_follows"` + Liked []User `gorm:"foreignkey:follower_id;associationforeignkey:userId;many2many:user_follows"` Md5 string `json:"md5"` Torrents []Torrents `gorm:"ForeignKey:UploaderId"` @@ -30,12 +30,8 @@ type PublicUser struct { User *User } -// UsersFollowers is a relation table to relate users each other. -type UsersFollowers struct { +// different users following eachother +type UserFollows struct { UserID uint `gorm:"column:user_id"` FollowerID uint `gorm:"column:following"` } - -func (c UsersFollowers) TableName() string { - return "user_follows" -}