Commit 2c435860 authored by Amos Wenger's avatar Amos Wenger

Fix has_many bug (with test coverage)

parent 9e88aa34
Pipeline #11367 passed with stage
in 27 seconds
......@@ -153,7 +153,7 @@ func Test_HasManyThorough(t *testing.T) {
ordie(err)
assert.EqualValues(t, numTraits, traitCount, "all traits should exist after save")
car.Traits = nil
car.Traits = car.Traits[:2]
ordie(c.Save(conn, car, hades.Assoc("Traits")))
......@@ -165,5 +165,5 @@ func Test_HasManyThorough(t *testing.T) {
traitCount, err = c.Count(conn, &Trait{}, builder.NewCond())
ordie(err)
assert.EqualValues(t, 0, traitCount, "no traits should exist after last save")
assert.EqualValues(t, 2, traitCount, "only the traist we want should exist after last save")
}
......@@ -196,7 +196,7 @@ func (c *Context) Save(conn *sqlite.Conn, rec interface{}, opts ...SaveParam) (e
passedPFs := make(map[interface{}]struct{})
for i := 0; i < v.Len(); i++ {
rec := v.Index(i)
pf := rec.Elem().FieldByName(rel.AssociationForeignDBNames[0]).Interface()
pf := rec.Elem().FieldByName(rel.AssociationForeignFieldNames[0]).Interface()
passedPFs[pf] = struct{}{}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment