mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 14:50:55 +00:00
fix values name
This commit is contained in:
parent
5ccdaeb09e
commit
250cbf593b
37
orm/db.go
37
orm/db.go
@ -231,7 +231,7 @@ func (t *dbTables) getJoinSql() (join string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dbTables) parseExprs(mi *modelInfo, exprs []string) (index, column string, info *fieldInfo, success bool) {
|
func (d *dbTables) parseExprs(mi *modelInfo, exprs []string) (index, column, name string, info *fieldInfo, success bool) {
|
||||||
var (
|
var (
|
||||||
ffi *fieldInfo
|
ffi *fieldInfo
|
||||||
jtl *dbTable
|
jtl *dbTable
|
||||||
@ -290,6 +290,11 @@ func (d *dbTables) parseExprs(mi *modelInfo, exprs []string) (index, column stri
|
|||||||
}
|
}
|
||||||
column = fi.column
|
column = fi.column
|
||||||
info = fi
|
info = fi
|
||||||
|
if jtl != nil {
|
||||||
|
name = jtl.name + ExprSep + fi.name
|
||||||
|
} else {
|
||||||
|
name = fi.name
|
||||||
|
}
|
||||||
|
|
||||||
switch fi.fieldType {
|
switch fi.fieldType {
|
||||||
case RelManyToMany, RelReverseMany:
|
case RelManyToMany, RelReverseMany:
|
||||||
@ -304,6 +309,7 @@ func (d *dbTables) parseExprs(mi *modelInfo, exprs []string) (index, column stri
|
|||||||
if exist == false {
|
if exist == false {
|
||||||
index = ""
|
index = ""
|
||||||
column = ""
|
column = ""
|
||||||
|
name = ""
|
||||||
success = false
|
success = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -349,7 +355,7 @@ func (d *dbTables) getCondSql(cond *Condition, sub bool) (where string, params [
|
|||||||
exprs = exprs[:num]
|
exprs = exprs[:num]
|
||||||
}
|
}
|
||||||
|
|
||||||
index, column, _, suc := d.parseExprs(mi, exprs)
|
index, column, _, _, suc := d.parseExprs(mi, exprs)
|
||||||
if suc == false {
|
if suc == false {
|
||||||
panic(fmt.Errorf("unknown field/column name `%s`", strings.Join(p.exprs, ExprSep)))
|
panic(fmt.Errorf("unknown field/column name `%s`", strings.Join(p.exprs, ExprSep)))
|
||||||
}
|
}
|
||||||
@ -387,7 +393,7 @@ func (d *dbTables) getOrderSql(orders []string) (orderSql string) {
|
|||||||
}
|
}
|
||||||
exprs := strings.Split(order, ExprSep)
|
exprs := strings.Split(order, ExprSep)
|
||||||
|
|
||||||
index, column, _, suc := d.parseExprs(d.mi, exprs)
|
index, column, _, _, suc := d.parseExprs(d.mi, exprs)
|
||||||
if suc == false {
|
if suc == false {
|
||||||
panic(fmt.Errorf("unknown field/column name `%s`", strings.Join(exprs, ExprSep)))
|
panic(fmt.Errorf("unknown field/column name `%s`", strings.Join(exprs, ExprSep)))
|
||||||
}
|
}
|
||||||
@ -1249,18 +1255,18 @@ func (d *dbBase) ReadValues(q dbQuerier, qs *querySet, mi *modelInfo, cond *Cond
|
|||||||
cols = make([]string, 0, len(exprs))
|
cols = make([]string, 0, len(exprs))
|
||||||
infos = make([]*fieldInfo, 0, len(exprs))
|
infos = make([]*fieldInfo, 0, len(exprs))
|
||||||
for _, ex := range exprs {
|
for _, ex := range exprs {
|
||||||
index, col, fi, suc := tables.parseExprs(mi, strings.Split(ex, ExprSep))
|
index, col, name, fi, suc := tables.parseExprs(mi, strings.Split(ex, ExprSep))
|
||||||
if suc == false {
|
if suc == false {
|
||||||
panic(fmt.Errorf("unknown field/column name `%s`", ex))
|
panic(fmt.Errorf("unknown field/column name `%s`", ex))
|
||||||
}
|
}
|
||||||
cols = append(cols, fmt.Sprintf("%s.`%s`", index, col))
|
cols = append(cols, fmt.Sprintf("%s.`%s` `%s`", index, col, name))
|
||||||
infos = append(infos, fi)
|
infos = append(infos, fi)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cols = make([]string, 0, len(mi.fields.dbcols))
|
cols = make([]string, 0, len(mi.fields.dbcols))
|
||||||
infos = make([]*fieldInfo, 0, len(exprs))
|
infos = make([]*fieldInfo, 0, len(exprs))
|
||||||
for _, fi := range mi.fields.fieldsDB {
|
for _, fi := range mi.fields.fieldsDB {
|
||||||
cols = append(cols, fmt.Sprintf("T0.`%s`", fi.column))
|
cols = append(cols, fmt.Sprintf("T0.`%s` `%s`", fi.column, fi.name))
|
||||||
infos = append(infos, fi)
|
infos = append(infos, fi)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1287,8 +1293,19 @@ func (d *dbBase) ReadValues(q dbQuerier, qs *querySet, mi *modelInfo, cond *Cond
|
|||||||
refs[i] = &ref
|
refs[i] = &ref
|
||||||
}
|
}
|
||||||
|
|
||||||
var cnt int64
|
var (
|
||||||
|
cnt int64
|
||||||
|
columns []string
|
||||||
|
)
|
||||||
for rs.Next() {
|
for rs.Next() {
|
||||||
|
if cnt == 0 {
|
||||||
|
if cols, err := rs.Columns(); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else {
|
||||||
|
columns = cols
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := rs.Scan(refs...); err != nil {
|
if err := rs.Scan(refs...); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
@ -1306,11 +1323,7 @@ func (d *dbBase) ReadValues(q dbQuerier, qs *querySet, mi *modelInfo, cond *Cond
|
|||||||
panic(fmt.Sprintf("db value convert failed `%v` %s", val, err.Error()))
|
panic(fmt.Sprintf("db value convert failed `%v` %s", val, err.Error()))
|
||||||
}
|
}
|
||||||
|
|
||||||
if hasExprs {
|
params[columns[i]] = value
|
||||||
params[exprs[i]] = value
|
|
||||||
} else {
|
|
||||||
params[mi.fields.dbcols[i]] = value
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
maps = append(maps, params)
|
maps = append(maps, params)
|
||||||
case 2:
|
case 2:
|
||||||
|
Loading…
Reference in New Issue
Block a user