Skip to content

Commit 83b9413

Browse files
committed
Change join order
1 parent b4cdfef commit 83b9413

1 file changed

Lines changed: 24 additions & 22 deletions

File tree

orm/join.go

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,6 @@ func (j *join) manyQuery(q *Query) (*Query, error) {
5050
}
5151

5252
q = q.Model(manyModel)
53-
if j.ApplyQuery != nil {
54-
var err error
55-
q, err = j.ApplyQuery(q)
56-
if err != nil {
57-
return nil, err
58-
}
59-
}
60-
61-
if len(q.columns) == 0 {
62-
q.columns = append(q.columns, &hasManyColumnsAppender{j})
63-
}
6453

6554
baseTable := j.BaseModel.Table()
6655
var where []byte
@@ -83,6 +72,18 @@ func (j *join) manyQuery(q *Query) (*Query, error) {
8372
baseTable.ModelName, baseTable.TypeName)
8473
}
8574

75+
if j.ApplyQuery != nil {
76+
var err error
77+
q, err = j.ApplyQuery(q)
78+
if err != nil {
79+
return nil, err
80+
}
81+
}
82+
83+
if len(q.columns) == 0 {
84+
q.columns = append(q.columns, &hasManyColumnsAppender{j})
85+
}
86+
8687
return q, nil
8788
}
8889

@@ -104,17 +105,6 @@ func (j *join) m2mQuery(fmter QueryFormatter, q *Query) (*Query, error) {
104105
}
105106

106107
q = q.Model(m2mModel)
107-
if j.ApplyQuery != nil {
108-
var err error
109-
q, err = j.ApplyQuery(q)
110-
if err != nil {
111-
return nil, err
112-
}
113-
}
114-
115-
if len(q.columns) == 0 {
116-
q.columns = append(q.columns, &hasManyColumnsAppender{j})
117-
}
118108

119109
index := j.JoinModel.ParentIndex()
120110
baseTable := j.BaseModel.Table()
@@ -150,6 +140,18 @@ func (j *join) m2mQuery(fmter QueryFormatter, q *Query) (*Query, error) {
150140
j.Rel.M2MTableAlias, types.Ident(col))
151141
}
152142

143+
if j.ApplyQuery != nil {
144+
var err error
145+
q, err = j.ApplyQuery(q)
146+
if err != nil {
147+
return nil, err
148+
}
149+
}
150+
151+
if len(q.columns) == 0 {
152+
q.columns = append(q.columns, &hasManyColumnsAppender{j})
153+
}
154+
153155
return q, nil
154156
}
155157

0 commit comments

Comments
 (0)