Don't need to delete join table records if no record added
This commit is contained in:
		
							parent
							
								
									cad0a42875
								
							
						
					
					
						commit
						7e8622f671
					
				@ -131,9 +131,11 @@ func (association *Association) Replace(values ...interface{}) *Association {
 | 
				
			|||||||
			addedPrimaryKeys = append(addedPrimaryKeys, primaryKey)
 | 
								addedPrimaryKeys = append(addedPrimaryKeys, primaryKey)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if len(addedPrimaryKeys) > 0 {
 | 
				
			||||||
			sql := fmt.Sprintf("%v = ? AND %v NOT IN (?)", scope.Quote(relationship.ForeignDBName), scope.Quote(relationship.AssociationForeignDBName))
 | 
								sql := fmt.Sprintf("%v = ? AND %v NOT IN (?)", scope.Quote(relationship.ForeignDBName), scope.Quote(relationship.AssociationForeignDBName))
 | 
				
			||||||
			query := scope.NewDB().Where(sql, association.PrimaryKey, addedPrimaryKeys)
 | 
								query := scope.NewDB().Where(sql, association.PrimaryKey, addedPrimaryKeys)
 | 
				
			||||||
			association.setErr(relationship.JoinTableHandler.Delete(query, relationship))
 | 
								association.setErr(relationship.JoinTableHandler.Delete(query, relationship))
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		association.setErr(errors.New("replace only support many to many"))
 | 
							association.setErr(errors.New("replace only support many to many"))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user