Add Joins
This commit is contained in:
		
							parent
							
								
									a158d1ada0
								
							
						
					
					
						commit
						5fce17543a
					
				| @ -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
									
								
							
							
						
						
									
										8
									
								
								clause/joins.go
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										10
									
								
								tests/joins.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,10 @@ | ||||
| package tests | ||||
| 
 | ||||
| import ( | ||||
| 	"testing" | ||||
| 
 | ||||
| 	"github.com/jinzhu/gorm" | ||||
| ) | ||||
| 
 | ||||
| func TestJoins(t *testing.T, db *gorm.DB) { | ||||
| } | ||||
| @ -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) { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Jinzhu
						Jinzhu