type Student struct {
ID int
Name string
Courses []Course `gorm:"many2many:student_courses;"`
}

type Course struct {
ID int
Name string
}

and I will get a table"student_courses,and if have three columns:"id,student_id,course_id"

and do i add a coulmn"score" in this table?and update it's value by the gorm?

Comment From: yp2800

The same issue. How to add extra field to middle table.

Comment From: jimanvlad

Based on the accepted answer here, it looks like creating a structure using both names works in creating the additional column:

type StudentCourse struct {
    Score uint
}

However, it is then unclear to me how to populate this column.

f1 := Student{
        ID:     1,
        Name:      "Student 1",
        Courses:     []Course{
            {
                ID:     1,
                Name:  "Economics",
            },
            {
                ID:     2,
                Name:  "Maths",
            },
        },
    }

db.Save(&f1)

The code above creates the corresponding many2many data in student_courses but not sure where in the code above I can add the score...

Comment From: github-actions[bot]

This issue will be automatically closed because it is marked as GORM V1 issue, we have released the public testing GORM V2 release and its documents https://v2.gorm.io/docs/ already, the testing release has been used in some production services for a while, and going to release the final version in following weeks, we are still actively collecting feedback before it, please open a new issue for any suggestion or problem, thank you

Also check out https://github.com/go-gorm/gorm/wiki/GORM-V2-Release-Note-Draft for how to use the public testing version and its changelog