Fixed associating benchmarks to test

This commit is contained in:
2025-07-14 13:53:50 -04:00
parent 9104125de7
commit 2b3f24ee5c

View File

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