We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
使用gorm 自引用多对多关系,如何反向查询呢? 比如:用户互相关注的表
Followers []*User `gorm:"many2many:follower;association_jointable_foreignkey:follow_id"` //用户关注表,自引用多对多关系。
查询用户的关注列表好做,如何查询关注用户(也就是用户的粉丝)列表?
The text was updated successfully, but these errors were encountered:
// FollowingIDs func func (u *User) FollowingIDs() []int { var ids []int rows, err := db.Table("follower").Where("follower_id = ?", u.ID).Select("user_id, follower_id").Rows() if err != nil { log.Println("Counting Following error:", err) return ids } defer rows.Close() for rows.Next() { var id, followerID int rows.Scan(&id, &followerID) ids = append(ids, id) } return ids }
将这个函数改改, .Where("follower_id = ?", u.ID) 改成 user_id = ? 试试,取出来的 follower_id 应该都是粉丝
.Where("follower_id = ?", u.ID)
user_id = ?
follower_id
Sorry, something went wrong.
No branches or pull requests
使用gorm 自引用多对多关系,如何反向查询呢?
比如:用户互相关注的表
查询用户的关注列表好做,如何查询关注用户(也就是用户的粉丝)列表?
The text was updated successfully, but these errors were encountered: