Commit 001e33f3 authored by slene's avatar slene

fix #213

parent 09aca252
......@@ -649,9 +649,12 @@ func (d *dbBase) ReadBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condi
if field.IsValid() {
d.setColsValues(mmi, &field, mmi.fields.dbcols, trefs[:len(mmi.fields.dbcols)], tz)
for _, fi := range mmi.fields.fieldsReverse {
if fi.reverseFieldInfo.mi == lastm {
if fi.inModel && fi.reverseFieldInfo.mi == lastm {
if fi.reverseFieldInfo != nil {
field.Field(fi.fieldIndex).Set(last.Addr())
f := field.Field(fi.fieldIndex)
if f.Kind() == reflect.Ptr {
f.Set(last.Addr())
}
}
}
}
......
......@@ -66,6 +66,7 @@ func newModelInfo(val reflect.Value) (info *modelInfo) {
fi.fieldIndex = i
fi.mi = info
fi.inModel = true
}
if err != nil {
......
......@@ -745,6 +745,17 @@ func TestRelatedSel(t *testing.T) {
num, err = qs.Filter("user__username", "slene").Count()
throwFail(t, err)
throwFail(t, AssertIs(num, 1))
var posts []*Post
qs = dORM.QueryTable("post")
num, err = qs.RelatedSel().All(&posts)
throwFail(t, err)
throwFailNow(t, AssertIs(num, 4))
throwFailNow(t, AssertIs(posts[0].User.UserName, "slene"))
throwFailNow(t, AssertIs(posts[1].User.UserName, "astaxie"))
throwFailNow(t, AssertIs(posts[2].User.UserName, "astaxie"))
throwFailNow(t, AssertIs(posts[3].User.UserName, "nobody"))
}
func TestSetCond(t *testing.T) {
......
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