Permalink
Browse files

Fix table names on joins when db has a namespace

This regression was introduced through parts of these commits:
- 8ee1f4d
- 1df6447
  • Loading branch information...
mraerino committed Jan 25, 2019
1 parent 3033540 commit 6885d7c1fd20b4098ab453b1bd8f3a86c3c9dacf
Showing with 5 additions and 3 deletions.
  1. +1 −1 api/download.go
  2. +1 −1 api/reports.go
  3. +1 −0 api/test.env
  4. +1 −1 api/user.go
  5. +1 −0 api/utils_test.go
@@ -110,7 +110,7 @@ func (a *API) DownloadList(w http.ResponseWriter, r *http.Request) error {
orderTable := a.db.NewScope(models.Order{}).QuotedTableName()
downloadsTable := a.db.NewScope(models.Download{}).QuotedTableName()

query := a.db.Joins("join " + orderTable + " as orders ON " + downloadsTable + ".order_id = " + orderTable + ".id and " + orderTable + ".payment_state = 'paid'")
query := a.db.Joins("join " + orderTable + " ON " + downloadsTable + ".order_id = " + orderTable + ".id and " + orderTable + ".payment_state = 'paid'")
if order != nil {
query = query.Where(orderTable+".id = ?", order.ID)
} else {
@@ -63,7 +63,7 @@ func (a *API) ProductsReport(w http.ResponseWriter, r *http.Request) error {
query := a.db.
Model(&models.LineItem{}).
Select("sku, path, sum(quantity * price) as total, currency").
Joins("JOIN " + ordersTable + " as orders " + "ON orders.id = " + itemsTable + ".order_id " + "AND orders.payment_state = 'paid'").
Joins("JOIN " + ordersTable + " ON " + ordersTable + ".id = " + itemsTable + ".order_id " + "AND " + ordersTable + ".payment_state = 'paid'").
Group("sku, path, currency").
Order("total desc")

@@ -4,6 +4,7 @@ GOCOMMERCE_JWT_AUD=api.netlify.com
GOCOMMERCE_DB_DRIVER=sqlite3
GOCOMMERCE_DB_AUTOMIGRATE=true
GOCOMMERCE_DB_DATABASE_URL=test.db
GOCOMMERCE_DB_NAMESPACE=test
GOCOMMERCE_API_HOST=localhost
PORT=9999
GOCOMMERCE_LOG_LEVEL=error
@@ -91,7 +91,7 @@ func (a *API) UserList(w http.ResponseWriter, r *http.Request) error {
orderTable := a.db.NewScope(models.Order{}).QuotedTableName()
userTable := a.db.NewScope(models.User{}).QuotedTableName()
query = query.
Joins("LEFT JOIN " + orderTable + " as orders ON " + userTable + ".id = " + orderTable + ".user_id").
Joins("LEFT JOIN " + orderTable + " ON " + userTable + ".id = " + orderTable + ".user_id").
Group(userTable + ".id")

instanceID := gcontext.GetInstanceID(r.Context())
@@ -69,6 +69,7 @@ func testConfig() (*conf.GlobalConfiguration, *conf.Configuration) {

globalConfig := new(conf.GlobalConfiguration)
globalConfig.DB.Automigrate = true
globalConfig.DB.Namespace = "test"

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

0 comments on commit 6885d7c

Please sign in to comment.