-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: support inner join * test: mixed inner join and left join * chore: code comment * Update statement.go Co-authored-by: Jinzhu <[email protected]>
- Loading branch information
1 parent
775fa70
commit 1935eb0
Showing
4 changed files
with
40 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -235,6 +235,16 @@ func (db *DB) Or(query interface{}, args ...interface{}) (tx *DB) { | |
// db.Joins("JOIN emails ON emails.user_id = users.id AND emails.email = ?", "[email protected]").Find(&user) | ||
// db.Joins("Account", DB.Select("id").Where("user_id = users.id AND name = ?", "someName").Model(&Account{})) | ||
func (db *DB) Joins(query string, args ...interface{}) (tx *DB) { | ||
return joins(db, clause.LeftJoin, query, args...) | ||
} | ||
|
||
// InnerJoins specify inner joins conditions | ||
// db.InnerJoins("Account").Find(&user) | ||
func (db *DB) InnerJoins(query string, args ...interface{}) (tx *DB) { | ||
return joins(db, clause.InnerJoin, query, args...) | ||
} | ||
|
||
func joins(db *DB, joinType clause.JoinType, query string, args ...interface{}) (tx *DB) { | ||
tx = db.getInstance() | ||
|
||
if len(args) == 1 { | ||
|
@@ -248,7 +258,7 @@ func (db *DB) Joins(query string, args ...interface{}) (tx *DB) { | |
} | ||
} | ||
|
||
tx.Statement.Joins = append(tx.Statement.Joins, join{Name: query, Conds: args}) | ||
tx.Statement.Joins = append(tx.Statement.Joins, join{Name: query, Conds: args, JoinType: joinType}) | ||
return | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters