소스 검색

Don't need NOT IN conditions when there are no primary keys found

Jinzhu 8 년 전
부모
커밋
934e97b018
1개의 변경된 파일4개의 추가작업 그리고 2개의 파일을 삭제
  1. 4 2
      association.go

+ 4 - 2
association.go

@@ -156,8 +156,10 @@ func (association *Association) Replace(values ...interface{}) *Association {
 			}
 
 			newPrimaryKeys = association.getPrimaryKeys(associationForeignFieldNames, field.Interface())
-			sql := fmt.Sprintf("%v NOT IN (%v)", toQueryCondition(scope, relationship.AssociationForeignDBNames), toQueryMarks(newPrimaryKeys))
-			newDB = newDB.Where(sql, toQueryValues(newPrimaryKeys)...)
+			if len(newPrimaryKeys) > 0 {
+				sql := fmt.Sprintf("%v NOT IN (%v)", toQueryCondition(scope, relationship.AssociationForeignDBNames), toQueryMarks(newPrimaryKeys))
+				newDB = newDB.Where(sql, toQueryValues(newPrimaryKeys)...)
+			}
 		}
 
 		if relationship.Kind == "many_to_many" {