From 5fce17543a2b166c915bff00ad2581ba1626255e Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sun, 8 Mar 2020 19:12:33 +0800 Subject: [PATCH] Add Joins --- chainable_api.go | 1 + clause/joins.go | 8 ++++++++ tests/joins.go | 10 ++++++++++ tests/tests.go | 1 + 4 files changed, 20 insertions(+) create mode 100644 clause/joins.go create mode 100644 tests/joins.go diff --git a/chainable_api.go b/chainable_api.go index f0bf8018..6f80d4be 100644 --- a/chainable_api.go +++ b/chainable_api.go @@ -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() diff --git a/clause/joins.go b/clause/joins.go new file mode 100644 index 00000000..4983d6fd --- /dev/null +++ b/clause/joins.go @@ -0,0 +1,8 @@ +package clause + +// Joins joins clause +type Joins struct { + Name string + Query string + Vars []interface{} +} diff --git a/tests/joins.go b/tests/joins.go new file mode 100644 index 00000000..3c4bfbb5 --- /dev/null +++ b/tests/joins.go @@ -0,0 +1,10 @@ +package tests + +import ( + "testing" + + "github.com/jinzhu/gorm" +) + +func TestJoins(t *testing.T, db *gorm.DB) { +} diff --git a/tests/tests.go b/tests/tests.go index 65c1ca96..33013032 100644 --- a/tests/tests.go +++ b/tests/tests.go @@ -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) {