Skip to content

Commit 33e2378

Browse files
committed
feat(jzero): To support join, the generated model with condition method will bring table by default for the columns that need to be selected.
1 parent dea6ee0 commit 33e2378

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

cmd/jzero/.template/go-zero/model/customized.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (m *custom{{.upperStartCamelObject}}Model) FindSelectedColumnsByCondition(c
2323
if len(columns) == 0 {
2424
columns = {{.lowerStartCamelObject}}FieldNames
2525
}
26-
sb := sqlbuilder.Select(columns...).From(m.table)
26+
sb := sqlbuilder.Select(m.withTableColumns(columns...)...).From(m.table)
2727
builder := condition.Select(*sb, conds...)
2828
statement, args := builder.Build()
2929

@@ -73,7 +73,7 @@ func (m *custom{{.upperStartCamelObject}}Model) CountByCondition(ctx context.Con
7373
}
7474

7575
func (m *custom{{.upperStartCamelObject}}Model) FindOneByCondition(ctx context.Context, session sqlx.Session, conds ...condition.Condition) (*{{.upperStartCamelObject}}, error) {
76-
sb := sqlbuilder.Select({{.lowerStartCamelObject}}FieldNames...).From(m.table)
76+
sb := sqlbuilder.Select(m.withTableColumns({{.lowerStartCamelObject}}FieldNames...)...).From(m.table)
7777

7878
builder := condition.Select(*sb, conds...)
7979
builder.Limit(1)
@@ -94,7 +94,7 @@ func (m *custom{{.upperStartCamelObject}}Model) FindOneByCondition(ctx context.C
9494
}
9595

9696
func (m *custom{{.upperStartCamelObject}}Model) PageByCondition(ctx context.Context, session sqlx.Session, conds ...condition.Condition) ([]*{{.upperStartCamelObject}}, int64 ,error) {
97-
sb := sqlbuilder.Select({{.lowerStartCamelObject}}FieldNames...).From(m.table)
97+
sb := sqlbuilder.Select(m.withTableColumns({{.lowerStartCamelObject}}FieldNames...)...).From(m.table)
9898
builder := condition.Select(*sb, conds...)
9999

100100
var resp []*{{.upperStartCamelObject}}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
func (m *default{{.upperStartCamelObject}}Model) TableName() string {
22
return m.table
33
}
4+
5+
func (m *default{{.upperStartCamelObject}}Model)withTableColumns(columns ...string) []string {
6+
var withTableColumns []string
7+
for _, col := range columns {
8+
if strings.Contains(col, ".") {
9+
withTableColumns = append(withTableColumns, col)
10+
} else {
11+
withTableColumns = append(withTableColumns, m.table + "." + col)
12+
}
13+
}
14+
return withTableColumns
15+
}

0 commit comments

Comments
 (0)