Fix an edge case for MySQL
- This patch removes auto-generation of queries that have the pattern COUNT(tablename.*) which is a syntax error in mysql.
This commit is contained in:
parent
468e2f9ad3
commit
1facccacc1
4 changed files with 18 additions and 1 deletions
|
@ -151,6 +151,11 @@ func SetLoad(q *Query, relationships ...string) {
|
|||
q.load = append([]string(nil), relationships...)
|
||||
}
|
||||
|
||||
// SetSelect on the query.
|
||||
func SetSelect(q *Query, sel []string) {
|
||||
q.selectCols = sel
|
||||
}
|
||||
|
||||
// SetCount on the query.
|
||||
func SetCount(q *Query) {
|
||||
q.count = true
|
||||
|
|
|
@ -58,7 +58,7 @@ func buildSelectQuery(q *Query) (*bytes.Buffer, []interface{}) {
|
|||
buf.WriteString(strings.Join(selectColsWithAs, ", "))
|
||||
} else if hasSelectCols {
|
||||
buf.WriteString(strings.Join(strmangle.IdentQuoteSlice(q.dialect.LQ, q.dialect.RQ, q.selectCols), ", "))
|
||||
} else if hasJoins {
|
||||
} else if hasJoins && !q.count {
|
||||
selectColsWithStars := writeStars(q)
|
||||
buf.WriteString(strings.Join(selectColsWithStars, ", "))
|
||||
} else {
|
||||
|
|
|
@ -290,6 +290,17 @@ func TestFrom(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestSetSelect(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
q := &Query{selectCols: []string{"hello"}}
|
||||
SetSelect(q, nil)
|
||||
|
||||
if q.selectCols != nil {
|
||||
t.Errorf("want nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
|
|
@ -79,6 +79,7 @@ func (q {{$varNameSingular}}Query) CountP() int64 {
|
|||
func (q {{$varNameSingular}}Query) Count() (int64, error) {
|
||||
var count int64
|
||||
|
||||
boil.SetSelect(q.Query, nil)
|
||||
boil.SetCount(q.Query)
|
||||
|
||||
err := boil.ExecQueryOne(q.Query).Scan(&count)
|
||||
|
|
Loading…
Add table
Reference in a new issue