Skip to content

Commit

Permalink
Add Joins
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Mar 8, 2020
1 parent a158d1a commit 5fce175
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions chainable_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func (db *DB) Or(query interface{}, args ...interface{}) (tx *DB) {
}

// Joins specify Joins conditions
// db.Joins("Account").Find(&user)
// db.Joins("JOIN emails ON emails.user_id = users.id AND emails.email = ?", "[email protected]").Find(&user)
func (db *DB) Joins(query string, args ...interface{}) (tx *DB) {
tx = db.getInstance()
Expand Down
8 changes: 8 additions & 0 deletions clause/joins.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package clause

// Joins joins clause
type Joins struct {
Name string
Query string
Vars []interface{}
}
10 changes: 10 additions & 0 deletions tests/joins.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package tests

import (
"testing"

"github.com/jinzhu/gorm"
)

func TestJoins(t *testing.T, db *gorm.DB) {
}
1 change: 1 addition & 0 deletions tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func RunTestsSuit(t *testing.T, db *gorm.DB) {
TestDelete(t, db)

TestGroupBy(t, db)
TestJoins(t, db)
}

func TestCreate(t *testing.T, db *gorm.DB) {
Expand Down

0 comments on commit 5fce175

Please sign in to comment.