Skip to content

Commit 6885d7c

Browse files
committed
Fix table names on joins when db has a namespace
This regression was introduced through parts of these commits: - 8ee1f4d - 1df6447
1 parent 3033540 commit 6885d7c

File tree

5 files changed

+5
-3
lines changed

5 files changed

+5
-3
lines changed

api/download.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (a *API) DownloadList(w http.ResponseWriter, r *http.Request) error {
110110
orderTable := a.db.NewScope(models.Order{}).QuotedTableName()
111111
downloadsTable := a.db.NewScope(models.Download{}).QuotedTableName()
112112

113-
query := a.db.Joins("join " + orderTable + " as orders ON " + downloadsTable + ".order_id = " + orderTable + ".id and " + orderTable + ".payment_state = 'paid'")
113+
query := a.db.Joins("join " + orderTable + " ON " + downloadsTable + ".order_id = " + orderTable + ".id and " + orderTable + ".payment_state = 'paid'")
114114
if order != nil {
115115
query = query.Where(orderTable+".id = ?", order.ID)
116116
} else {

api/reports.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (a *API) ProductsReport(w http.ResponseWriter, r *http.Request) error {
6363
query := a.db.
6464
Model(&models.LineItem{}).
6565
Select("sku, path, sum(quantity * price) as total, currency").
66-
Joins("JOIN " + ordersTable + " as orders " + "ON orders.id = " + itemsTable + ".order_id " + "AND orders.payment_state = 'paid'").
66+
Joins("JOIN " + ordersTable + " ON " + ordersTable + ".id = " + itemsTable + ".order_id " + "AND " + ordersTable + ".payment_state = 'paid'").
6767
Group("sku, path, currency").
6868
Order("total desc")
6969

api/test.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ GOCOMMERCE_JWT_AUD=api.netlify.com
44
GOCOMMERCE_DB_DRIVER=sqlite3
55
GOCOMMERCE_DB_AUTOMIGRATE=true
66
GOCOMMERCE_DB_DATABASE_URL=test.db
7+
GOCOMMERCE_DB_NAMESPACE=test
78
GOCOMMERCE_API_HOST=localhost
89
PORT=9999
910
GOCOMMERCE_LOG_LEVEL=error

api/user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (a *API) UserList(w http.ResponseWriter, r *http.Request) error {
9191
orderTable := a.db.NewScope(models.Order{}).QuotedTableName()
9292
userTable := a.db.NewScope(models.User{}).QuotedTableName()
9393
query = query.
94-
Joins("LEFT JOIN " + orderTable + " as orders ON " + userTable + ".id = " + orderTable + ".user_id").
94+
Joins("LEFT JOIN " + orderTable + " ON " + userTable + ".id = " + orderTable + ".user_id").
9595
Group(userTable + ".id")
9696

9797
instanceID := gcontext.GetInstanceID(r.Context())

api/utils_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func testConfig() (*conf.GlobalConfiguration, *conf.Configuration) {
6969

7070
globalConfig := new(conf.GlobalConfiguration)
7171
globalConfig.DB.Automigrate = true
72+
globalConfig.DB.Namespace = "test"
7273

7374
config := new(conf.Configuration)
7475
config.JWT.Secret = "testsecret"

0 commit comments

Comments
 (0)