1
0
mirror of https://github.com/beego/bee.git synced 2024-11-22 20:20:55 +00:00

增加关联查询 RelatedSel()

This commit is contained in:
qida 2016-09-10 18:47:57 +08:00
parent 8058ab37b8
commit 394df69d36
3 changed files with 6 additions and 6 deletions

View File

@ -1046,7 +1046,7 @@ func Add{{modelName}}(m *{{modelName}}) (id int64, err error) {
func Get{{modelName}}ById(id int) (v *{{modelName}}, err error) {
o := orm.NewOrm()
v = &{{modelName}}{Id: id}
if err = o.Read(v); err == nil {
if err = o.QueryTable(new({{modelName}})).Filter("Id", id).RelatedSel().One(v); err == nil {
return v, nil
}
return nil, err
@ -1105,7 +1105,7 @@ func GetAll{{modelName}}(query map[string]string, fields []string, sortby []stri
var l []{{modelName}}
qs = qs.OrderBy(sortFields...)
if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
if _, err = qs.Limit(limit, offset).RelatedSel().All(&l, fields...); err == nil {
if len(fields) == 0 {
for _, v := range l {
ml = append(ml, v)

View File

@ -204,7 +204,7 @@ func Add{{modelName}}(m *{{modelName}}) (id int64, err error) {
func Get{{modelName}}ById(id int) (v *{{modelName}}, err error) {
o := orm.NewOrm()
v = &{{modelName}}{Id: id}
if err = o.Read(v); err == nil {
if err = o.QueryTable(new({{modelName}})).Filter("Id", id).RelatedSel().One(v); err == nil {
return v, nil
}
return nil, err
@ -263,7 +263,7 @@ func GetAll{{modelName}}(query map[string]string, fields []string, sortby []stri
var l []{{modelName}}
qs = qs.OrderBy(sortFields...)
if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
if _, err = qs.Limit(limit, offset).RelatedSel().All(&l, fields...); err == nil {
if len(fields) == 0 {
for _, v := range l {
ml = append(ml, v)

View File

@ -166,7 +166,7 @@ func Add{{modelName}}(m *{{modelName}}) (id int64, err error) {
func Get{{modelName}}ById(id int64) (v *{{modelName}}, err error) {
o := orm.NewOrm()
v = &{{modelName}}{Id: id}
if err = o.Read(v); err == nil {
if err = o.QueryTable(new({{modelName}})).Filter("Id", id).RelatedSel().One(v); err == nil {
return v, nil
}
return nil, err
@ -225,7 +225,7 @@ func GetAll{{modelName}}(query map[string]string, fields []string, sortby []stri
var l []{{modelName}}
qs = qs.OrderBy(sortFields...)
if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
if _, err = qs.Limit(limit, offset).RelatedSel().All(&l, fields...); err == nil {
if len(fields) == 0 {
for _, v := range l {
ml = append(ml, v)