mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 22:00:55 +00:00
commit
7b542e612f
@ -1064,12 +1064,17 @@ func (d *dbBase) Count(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condition
|
|||||||
tables.parseRelated(qs.related, qs.relDepth)
|
tables.parseRelated(qs.related, qs.relDepth)
|
||||||
|
|
||||||
where, args := tables.getCondSQL(cond, false, tz)
|
where, args := tables.getCondSQL(cond, false, tz)
|
||||||
|
groupBy := tables.getGroupSQL(qs.groups)
|
||||||
tables.getOrderSQL(qs.orders)
|
tables.getOrderSQL(qs.orders)
|
||||||
join := tables.getJoinSQL()
|
join := tables.getJoinSQL()
|
||||||
|
|
||||||
Q := d.ins.TableQuote()
|
Q := d.ins.TableQuote()
|
||||||
|
|
||||||
query := fmt.Sprintf("SELECT COUNT(*) FROM %s%s%s T0 %s%s", Q, mi.table, Q, join, where)
|
query := fmt.Sprintf("SELECT COUNT(*) FROM %s%s%s T0 %s%s%s", Q, mi.table, Q, join, where, groupBy)
|
||||||
|
|
||||||
|
if groupBy != "" {
|
||||||
|
query = fmt.Sprintf("SELECT COUNT(*) FROM (%s) AS T", query)
|
||||||
|
}
|
||||||
|
|
||||||
d.ins.ReplaceMarks(&query)
|
d.ins.ReplaceMarks(&query)
|
||||||
|
|
||||||
|
@ -342,7 +342,13 @@ func (o *rawSet) QueryRow(containers ...interface{}) error {
|
|||||||
for _, col := range columns {
|
for _, col := range columns {
|
||||||
if fi := sMi.fields.GetByColumn(col); fi != nil {
|
if fi := sMi.fields.GetByColumn(col); fi != nil {
|
||||||
value := reflect.ValueOf(columnsMp[col]).Elem().Interface()
|
value := reflect.ValueOf(columnsMp[col]).Elem().Interface()
|
||||||
o.setFieldValue(ind.FieldByIndex(fi.fieldIndex), value)
|
field := ind.FieldByIndex(fi.fieldIndex)
|
||||||
|
if fi.fieldType&IsRelField > 0 {
|
||||||
|
mf := reflect.New(fi.relModelInfo.addrField.Elem().Type())
|
||||||
|
field.Set(mf)
|
||||||
|
field = mf.Elem().FieldByIndex(fi.relModelInfo.fields.pk.fieldIndex)
|
||||||
|
}
|
||||||
|
o.setFieldValue(field, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -480,7 +486,13 @@ func (o *rawSet) QueryRows(containers ...interface{}) (int64, error) {
|
|||||||
for _, col := range columns {
|
for _, col := range columns {
|
||||||
if fi := sMi.fields.GetByColumn(col); fi != nil {
|
if fi := sMi.fields.GetByColumn(col); fi != nil {
|
||||||
value := reflect.ValueOf(columnsMp[col]).Elem().Interface()
|
value := reflect.ValueOf(columnsMp[col]).Elem().Interface()
|
||||||
o.setFieldValue(ind.FieldByIndex(fi.fieldIndex), value)
|
field := ind.FieldByIndex(fi.fieldIndex)
|
||||||
|
if fi.fieldType&IsRelField > 0 {
|
||||||
|
mf := reflect.New(fi.relModelInfo.addrField.Elem().Type())
|
||||||
|
field.Set(mf)
|
||||||
|
field = mf.Elem().FieldByIndex(fi.relModelInfo.fields.pk.fieldIndex)
|
||||||
|
}
|
||||||
|
o.setFieldValue(field, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user