I am working on a project and relatively new to Golang. I am using GORM
for my Database ORM. I don't know what I am doing wrong but I can't get to create records with associations.
type (
Task struct {
gorm.Model
Title string `json:"title"`
Description string `json:"description"`
Priority Priority `json:"priority_id" validate:"required" gorm:"foreignkey:PriorityID"`
PriorityID uint
}
Priority struct {
gorm.Model
Name string `json:"name"`
}
)
And when I do
task := Task{
Title: "Test Task!",
Description: "Test Task Description",
Priority: Priority{ID: 1},
}
db.Create(&task)
It throws me this error:
[2019-07-27 18:34:35] sql: converting argument $7 type: unsupported type models.Priority, a struct
I had a look at GORM Associations but couldn't really find any solution which could make it work.