GORM v1.25.1,我在Worker
、Poster
和Job
型号上运行DB.AutoMigrate()
,但在[error] unsupported data type: &[]
上运行.Worker和Job struct 应该有many-to-many relation
,而Poster和Job应该有one-to-many
个关系.工作者和经验、工作者和偏好都应该是one-to-many
的关系.请帮帮忙.
package model
type experience struct {
gorm.Model
Company int `json:"company"`
JobTitle string `json:"jobTitle"`
WorkerID uint
}
type preference struct {
gorm.Model
JobTitle string `json:"JobTitle"`
MinPay int `json:"minPay"`
MaxPay int `json:"maxPay"`
WorkerID uint
}
type Worker struct {
gorm.Model
Username string `gorm:"uniqueIndex;not null" json:"username"`
...more fields
Experience []experience `json:"experience"`
Preference []preference `json:"preference"`
AppliedJobs []Job `gorm:"many2many:worker_jobs;" json:"appliedJobs"`
}
type Poster struct {
gorm.Model
Name string `gorm:"uniqueIndex;not null" json:"name"`
Email string `gorm:"uniqueIndex;not null" json:"email"`
Phone string `json:"phone"`
JobsPosted []Job `json:"jobsPosted"`
}
type Job struct {
gorm.Model
Title string `gorm:"uniqueIndex;not null" json:"title"`
...more fields
PosterID uint `json:"posterID"`
}