mirror of
https://github.com/beego/bee.git
synced 2024-11-21 18:40:54 +00:00
增加关联查询
This commit is contained in:
parent
3be35d9d81
commit
a353b6d69a
@ -1026,7 +1026,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
|
||||
@ -1089,7 +1089,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)
|
||||
|
@ -441,7 +441,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
|
||||
@ -500,7 +500,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)
|
||||
|
@ -167,7 +167,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
|
||||
@ -226,7 +226,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)
|
||||
|
Loading…
Reference in New Issue
Block a user