1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-25 21:11:29 +00:00
This commit is contained in:
slene 2014-01-04 22:30:17 +08:00
parent ef79a2b484
commit 95c65de97c
2 changed files with 85 additions and 29 deletions

View File

@ -112,7 +112,7 @@ func (t *dbTables) parseRelated(rels []string, depth int) {
names = append(names, fi.name) names = append(names, fi.name)
mmi = fi.relModelInfo mmi = fi.relModelInfo
if fi.null { if fi.null || t.skipEnd {
inner = false inner = false
} }
@ -189,6 +189,8 @@ func (t *dbTables) getJoinSql() (join string) {
func (t *dbTables) parseExprs(mi *modelInfo, exprs []string) (index, name string, info *fieldInfo, success bool) { func (t *dbTables) parseExprs(mi *modelInfo, exprs []string) (index, name string, info *fieldInfo, success bool) {
var ( var (
jtl *dbTable jtl *dbTable
fi *fieldInfo
fiN *fieldInfo
mmi = mi mmi = mi
) )
@ -197,9 +199,24 @@ func (t *dbTables) parseExprs(mi *modelInfo, exprs []string) (index, name string
inner := true inner := true
loopFor:
for i, ex := range exprs { for i, ex := range exprs {
fi, ok := mmi.fields.GetByAny(ex) var ok, okN bool
if fiN != nil {
fi = fiN
ok = true
fiN = nil
}
if i == 0 {
fi, ok = mmi.fields.GetByAny(ex)
}
// fmt.Println(ex, fi.name, fiN)
_ = okN
if ok { if ok {
@ -217,13 +234,20 @@ func (t *dbTables) parseExprs(mi *modelInfo, exprs []string) (index, name string
mmi = fi.reverseFieldInfo.mi mmi = fi.reverseFieldInfo.mi
} }
if i < num {
fiN, okN = mmi.fields.GetByAny(exprs[i+1])
}
if isRel && (fi.mi.isThrough == false || num != i) { if isRel && (fi.mi.isThrough == false || num != i) {
if fi.null { if fi.null || t.skipEnd {
inner = false inner = false
} }
if num == i && t.skipEnd { if t.skipEnd && okN || !t.skipEnd {
} else { if t.skipEnd && okN && fiN.pk {
goto loopEnd
}
jt, _ := t.add(names, mmi, fi, inner) jt, _ := t.add(names, mmi, fi, inner)
jt.jtl = jtl jt.jtl = jtl
jtl = jt jtl = jt
@ -231,7 +255,12 @@ func (t *dbTables) parseExprs(mi *modelInfo, exprs []string) (index, name string
} }
if num == i { if num != i {
continue
}
loopEnd:
if i == 0 || jtl == nil { if i == 0 || jtl == nil {
index = "T0" index = "T0"
} else { } else {
@ -257,7 +286,8 @@ func (t *dbTables) parseExprs(mi *modelInfo, exprs []string) (index, name string
name = info.name name = info.name
} }
} }
}
break loopFor
} else { } else {
index = "" index = ""

View File

@ -1561,6 +1561,32 @@ func TestDelete(t *testing.T) {
num, err = qs.Filter("user_name", "slene").Filter("profile__isnull", true).Count() num, err = qs.Filter("user_name", "slene").Filter("profile__isnull", true).Count()
throwFail(t, err) throwFail(t, err)
throwFail(t, AssertIs(num, 1)) throwFail(t, AssertIs(num, 1))
qs = dORM.QueryTable("comment")
num, err = qs.Count()
throwFail(t, err)
throwFail(t, AssertIs(num, 6))
qs = dORM.QueryTable("post")
num, err = qs.Filter("Id", 3).Delete()
throwFail(t, err)
throwFail(t, AssertIs(num, 1))
qs = dORM.QueryTable("comment")
num, err = qs.Count()
throwFail(t, err)
throwFail(t, AssertIs(num, 4))
fmt.Println("...")
qs = dORM.QueryTable("comment")
num, err = qs.Filter("Post__User", 3).Delete()
throwFail(t, err)
throwFail(t, AssertIs(num, 3))
qs = dORM.QueryTable("comment")
num, err = qs.Count()
throwFail(t, err)
throwFail(t, AssertIs(num, 1))
} }
func TestTransaction(t *testing.T) { func TestTransaction(t *testing.T) {