Add Joins

This commit is contained in:
Jinzhu 2020-03-08 19:12:33 +08:00
parent a158d1ada0
commit 5fce17543a
4 changed files with 20 additions and 0 deletions

View File

@ -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 = ?", "jinzhu@example.org").Find(&user)
func (db *DB) Joins(query string, args ...interface{}) (tx *DB) {
tx = db.getInstance()

8
clause/joins.go Normal file
View File

@ -0,0 +1,8 @@
package clause
// Joins joins clause
type Joins struct {
Name string
Query string
Vars []interface{}
}

10
tests/joins.go Normal file
View File

@ -0,0 +1,10 @@
package tests
import (
"testing"
"github.com/jinzhu/gorm"
)
func TestJoins(t *testing.T, db *gorm.DB) {
}

View File

@ -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) {