Your issue may already be reported! Please search on the issue track before creating one.

What version of Go are you using (go version)?

go version go1.13.5 darwin/amd64

Which database and its version are you using?

mysql ( base on vagrant )

Please provide a complete runnable program to reproduce your issue. IMPORTANT

Need to runnable with GORM's docker compose config or please provides your config.

package main

import (
    "github.com/jinzhu/gorm"
    _ "github.com/jinzhu/gorm/dialects/mysql"
    "github.com/uniplaces/carbon"
)

var db *gorm.DB

func init() {
    var err error
    db, err = gorm.Open("mysql", "gorm:gorm@tcp(localhost:9910)/gorm?charset=utf8&parseTime=True")
    if err != nil {
        panic(err)
    }
    db.LogMode(true)
}
var User struct {
   id uint `json:"id"`
   Email string `json:"string"`
  ......// other field
   Roles    []Role  `gorm:"many2many:role_users;" json:"-"`
}
var Role struct {
   id uint `json:"id"`
   name string `json:"name"`
  ....// other field
}
var RoleUser {
   RoleId uint `json:"role_id"`
   Role Role  `gorm:"-"`
   UserId uint `json:"user_id"`
   User User  `gorm:"-"`
   ExpiredAt  time.Time `json:"expired_at"` // how to add this field on many2many first create
}



func main() {
    // eg 
 if err :=    db.Where("id = ? ", 1 ).First(&user).error; err == nil{
    db.Where("id = ? ", 3 ).Find(&role)
   expired_at := carbon.Now().AddMonths(3)
  // the expired_at field how to insert into table with association
    db.Model(&user).Association("Roles").Append(&role)
   -----------------------------------------------------------------------
  // other available method
  var ru RoleUser
  ru.ExpiredAt = carbon.Now().AddMonths(3).Time
  db.Save(&ru) // useful
}
}

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

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

Comment From: ianprogrammer

@svcg did you find the solution ?

Comment From: sneko

@cleveng @ianprogrammer did you at the end?

EDIT: ok it seems https://github.com/go-gorm/gorm.io/commit/654fd7e8b5e2f431b4f104653f483dd83b841c41 could do the trick since the third struct exists in my code