1
0
mirror of https://github.com/astaxie/beego.git synced 2024-06-18 12:54:14 +00:00
This commit is contained in:
slene 2013-09-22 19:20:40 +08:00
parent 09aca2528a
commit 001e33f310
3 changed files with 17 additions and 2 deletions

View File

@ -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())
}
}
}
}

View File

@ -66,6 +66,7 @@ func newModelInfo(val reflect.Value) (info *modelInfo) {
fi.fieldIndex = i
fi.mi = info
fi.inModel = true
}
if err != nil {

View File

@ -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) {