go-gorm / gorm.io

GORM official site

Home Page:https://gorm.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Self-Referential Many2Many Table need an extra column

manalivaltix opened this issue · comments

Document Link

Hello,
I want to use a self-referential many2many table association. The problem is I want to add an extra column "accepted" = true or fals, in the join-table

type User struct {
gorm.Model
MutualFriends []*User gorm:"many2many:friendships;association_jointable_foreignkey:friend_id" // accepted = true
Friends []*User gorm:"many2many:friendships;association_jointable_foreignkey:friend_id" // accepeted = false
}

How do I capture this? I am wondering if I should stop using gorm "definitions" to define the join table, and just have a separate model for friendships?

Your Question

Expected answer