I use Golang and GORM.
I have a User
structure which has one Association
.
type User struct {
ID int
...
}
type Association struct {
ID int
UserID int
}
I also have an AssoUser
structure, which is composed of a anonymous field User
, and has a pointer to Assocation
.
type AssoUser struct {
User
Asso *Association
}
When I run
var assoUser AssoUser
assoUser.Asso = &Association{
Name : "asso_name",
...
}
assoUser.Name = "user_name"
...
// filling the struct
db.Debug().Create(&assoUser)
I expect it to create the User
AND the Association
, but it only creates the User.
What am I doing wrong ?