mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 02:20:54 +00:00
fix #213
This commit is contained in:
parent
09aca2528a
commit
001e33f310
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user