Merge a9d11a9cc8a013a94c296db5a79fe75ad415df5e into 5663048f137b961f9b1bac6a10227096aa36b0bf
This commit is contained in:
		
						commit
						5576102c6a
					
				@ -8,7 +8,7 @@ import (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type JoinTableHandlerInterface interface {
 | 
					type JoinTableHandlerInterface interface {
 | 
				
			||||||
	Setup(relationship *Relationship, tableName string, source reflect.Type, destination reflect.Type)
 | 
						Setup(db *DB, relationship *Relationship, tableName string, source reflect.Type, destination reflect.Type)
 | 
				
			||||||
	Table(db *DB) string
 | 
						Table(db *DB) string
 | 
				
			||||||
	Add(handler JoinTableHandlerInterface, db *DB, source interface{}, destination interface{}) error
 | 
						Add(handler JoinTableHandlerInterface, db *DB, source interface{}, destination interface{}) error
 | 
				
			||||||
	Delete(handler JoinTableHandlerInterface, db *DB, sources ...interface{}) error
 | 
						Delete(handler JoinTableHandlerInterface, db *DB, sources ...interface{}) error
 | 
				
			||||||
@ -41,7 +41,7 @@ func (s *JoinTableHandler) DestinationForeignKeys() []JoinTableForeignKey {
 | 
				
			|||||||
	return s.Destination.ForeignKeys
 | 
						return s.Destination.ForeignKeys
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s *JoinTableHandler) Setup(relationship *Relationship, tableName string, source reflect.Type, destination reflect.Type) {
 | 
					func (s *JoinTableHandler) Setup(db *DB, relationship *Relationship, tableName string, source reflect.Type, destination reflect.Type) {
 | 
				
			||||||
	s.TableName = tableName
 | 
						s.TableName = tableName
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	s.Source = JoinTableSource{ModelType: source}
 | 
						s.Source = JoinTableSource{ModelType: source}
 | 
				
			||||||
@ -68,6 +68,7 @@ func (s *JoinTableHandler) Setup(relationship *Relationship, tableName string, s
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	s.Destination = JoinTableSource{ModelType: destination}
 | 
						s.Destination = JoinTableSource{ModelType: destination}
 | 
				
			||||||
	destinationScope := &Scope{Value: reflect.New(destination).Interface()}
 | 
						destinationScope := &Scope{Value: reflect.New(destination).Interface()}
 | 
				
			||||||
 | 
						destinationScope.db = db
 | 
				
			||||||
	destinationPrimaryFields := destinationScope.GetModelStruct().PrimaryFields
 | 
						destinationPrimaryFields := destinationScope.GetModelStruct().PrimaryFields
 | 
				
			||||||
	for _, primaryField := range destinationPrimaryFields {
 | 
						for _, primaryField := range destinationPrimaryFields {
 | 
				
			||||||
		var dbName string
 | 
							var dbName string
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								main.go
									
									
									
									
									
								
							@ -485,7 +485,7 @@ func (s *DB) SetJoinTableHandler(source interface{}, column string, handler Join
 | 
				
			|||||||
			if many2many := parseTagSetting(field.Tag.Get("gorm"))["MANY2MANY"]; many2many != "" {
 | 
								if many2many := parseTagSetting(field.Tag.Get("gorm"))["MANY2MANY"]; many2many != "" {
 | 
				
			||||||
				source := (&Scope{Value: source}).GetModelStruct().ModelType
 | 
									source := (&Scope{Value: source}).GetModelStruct().ModelType
 | 
				
			||||||
				destination := (&Scope{Value: reflect.New(field.Struct.Type).Interface()}).GetModelStruct().ModelType
 | 
									destination := (&Scope{Value: reflect.New(field.Struct.Type).Interface()}).GetModelStruct().ModelType
 | 
				
			||||||
				handler.Setup(field.Relationship, many2many, source, destination)
 | 
									handler.Setup(s, field.Relationship, many2many, source, destination)
 | 
				
			||||||
				field.Relationship.JoinTableHandler = handler
 | 
									field.Relationship.JoinTableHandler = handler
 | 
				
			||||||
				if table := handler.Table(s); scope.Dialect().HasTable(scope, table) {
 | 
									if table := handler.Table(s); scope.Dialect().HasTable(scope, table) {
 | 
				
			||||||
					s.Table(table).AutoMigrate(handler)
 | 
										s.Table(table).AutoMigrate(handler)
 | 
				
			||||||
 | 
				
			|||||||
@ -229,7 +229,7 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
 | 
				
			|||||||
								relationship.AssociationForeignDBName = ToDBName(associationForeignKey)
 | 
													relationship.AssociationForeignDBName = ToDBName(associationForeignKey)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
								joinTableHandler := JoinTableHandler{}
 | 
													joinTableHandler := JoinTableHandler{}
 | 
				
			||||||
								joinTableHandler.Setup(relationship, many2many, scopeType, elemType)
 | 
													joinTableHandler.Setup(scope.db, relationship, many2many, scopeType, elemType)
 | 
				
			||||||
								relationship.JoinTableHandler = &joinTableHandler
 | 
													relationship.JoinTableHandler = &joinTableHandler
 | 
				
			||||||
								field.Relationship = relationship
 | 
													field.Relationship = relationship
 | 
				
			||||||
							} else {
 | 
												} else {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user