fix: DB: Submission nested preload
This commit is contained in:
parent
de95e8c804
commit
1a5b8270ef
@ -4,7 +4,8 @@ import "gorm.io/gorm"
|
|||||||
|
|
||||||
type Submission struct {
|
type Submission struct {
|
||||||
gorm.Model `json:"meta"`
|
gorm.Model `json:"meta"`
|
||||||
ProblemID uint `json:"problem_id" gorm:"not null;index"`
|
ProblemID uint `json:"-" gorm:"not null;index"`
|
||||||
|
Problem Problem `json:"problem" gorm:"foreignKey:ProblemID"`
|
||||||
UserID uint `json:"-" gorm:"not null;index"`
|
UserID uint `json:"-" gorm:"not null;index"`
|
||||||
User User `json:"user" gorm:"foreignKey:UserID"`
|
User User `json:"user" gorm:"foreignKey:UserID"`
|
||||||
Language string `json:"language" gorm:"not null"`
|
Language string `json:"language" gorm:"not null"`
|
||||||
|
@ -18,7 +18,10 @@ func (s *service) Query(sid uint, associations bool) (*model.Status, e.Status) {
|
|||||||
|
|
||||||
query := s.db.Get()
|
query := s.db.Get()
|
||||||
if associations {
|
if associations {
|
||||||
query = query.Preload(clause.Associations)
|
query = query.
|
||||||
|
Preload("Submission.Problem").
|
||||||
|
Preload("Submission.User").
|
||||||
|
Preload(clause.Associations)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := query.
|
err := query.
|
||||||
@ -43,7 +46,8 @@ func (s *service) QueryByVersion(pvid uint, offset int, limit int, count *int64)
|
|||||||
IsEnabled: true,
|
IsEnabled: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := s.db.Get().Preload(clause.Associations).
|
err := s.db.Get().
|
||||||
|
Preload("Submission.Problem").Preload("Submission.User").Preload(clause.Associations).
|
||||||
Where(status).
|
Where(status).
|
||||||
Order("created_at DESC").
|
Order("created_at DESC").
|
||||||
Offset(offset).Limit(limit).Find(&ret).
|
Offset(offset).Limit(limit).Find(&ret).
|
||||||
|
Loading…
Reference in New Issue
Block a user