fix #213
Showing
3 changed files
with
17 additions
and
2 deletions
| ... | @@ -649,9 +649,12 @@ func (d *dbBase) ReadBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condi | ... | @@ -649,9 +649,12 @@ func (d *dbBase) ReadBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condi |
| 649 | if field.IsValid() { | 649 | if field.IsValid() { |
| 650 | d.setColsValues(mmi, &field, mmi.fields.dbcols, trefs[:len(mmi.fields.dbcols)], tz) | 650 | d.setColsValues(mmi, &field, mmi.fields.dbcols, trefs[:len(mmi.fields.dbcols)], tz) |
| 651 | for _, fi := range mmi.fields.fieldsReverse { | 651 | for _, fi := range mmi.fields.fieldsReverse { |
| 652 | if fi.reverseFieldInfo.mi == lastm { | 652 | if fi.inModel && fi.reverseFieldInfo.mi == lastm { |
| 653 | if fi.reverseFieldInfo != nil { | 653 | if fi.reverseFieldInfo != nil { |
| 654 | field.Field(fi.fieldIndex).Set(last.Addr()) | 654 | f := field.Field(fi.fieldIndex) |
| 655 | if f.Kind() == reflect.Ptr { | ||
| 656 | f.Set(last.Addr()) | ||
| 657 | } | ||
| 655 | } | 658 | } |
| 656 | } | 659 | } |
| 657 | } | 660 | } | ... | ... |
| ... | @@ -66,6 +66,7 @@ func newModelInfo(val reflect.Value) (info *modelInfo) { | ... | @@ -66,6 +66,7 @@ func newModelInfo(val reflect.Value) (info *modelInfo) { |
| 66 | 66 | ||
| 67 | fi.fieldIndex = i | 67 | fi.fieldIndex = i |
| 68 | fi.mi = info | 68 | fi.mi = info |
| 69 | fi.inModel = true | ||
| 69 | } | 70 | } |
| 70 | 71 | ||
| 71 | if err != nil { | 72 | if err != nil { | ... | ... |
| ... | @@ -745,6 +745,17 @@ func TestRelatedSel(t *testing.T) { | ... | @@ -745,6 +745,17 @@ func TestRelatedSel(t *testing.T) { |
| 745 | num, err = qs.Filter("user__username", "slene").Count() | 745 | num, err = qs.Filter("user__username", "slene").Count() |
| 746 | throwFail(t, err) | 746 | throwFail(t, err) |
| 747 | throwFail(t, AssertIs(num, 1)) | 747 | throwFail(t, AssertIs(num, 1)) |
| 748 | |||
| 749 | var posts []*Post | ||
| 750 | qs = dORM.QueryTable("post") | ||
| 751 | num, err = qs.RelatedSel().All(&posts) | ||
| 752 | throwFail(t, err) | ||
| 753 | throwFailNow(t, AssertIs(num, 4)) | ||
| 754 | |||
| 755 | throwFailNow(t, AssertIs(posts[0].User.UserName, "slene")) | ||
| 756 | throwFailNow(t, AssertIs(posts[1].User.UserName, "astaxie")) | ||
| 757 | throwFailNow(t, AssertIs(posts[2].User.UserName, "astaxie")) | ||
| 758 | throwFailNow(t, AssertIs(posts[3].User.UserName, "nobody")) | ||
| 748 | } | 759 | } |
| 749 | 760 | ||
| 750 | func TestSetCond(t *testing.T) { | 761 | func TestSetCond(t *testing.T) { | ... | ... |
-
Please register or sign in to post a comment