Fixed associating benchmarks to test

This commit is contained in:
Gregory Ballantine 2024-05-29 10:07:15 -04:00
parent 2be6d216d1
commit e3e4e24e56

View File

@ -72,9 +72,11 @@ func TestPostCreate(c flamego.Context, form forms.TestForm, errs binding.Errors)
_ = models.DB.Create(&test) _ = models.DB.Create(&test)
// bind benchmarks to test
for _, v := range form.Benchmarks { for _, v := range form.Benchmarks {
fmt.Printf("%s", v) var benchmark models.Benchmark
test.Association("Benchmarks").Append(models.Benchmark{ID: v}) models.DB.First(&benchmark, v) // find benchmark
models.DB.Model(&test).Association("Benchmarks").Append(&benchmark)
} }
c.Redirect(fmt.Sprintf("/test/%d", test.ID)) c.Redirect(fmt.Sprintf("/test/%d", test.ID))