From 934e97b0181a534aa5dd164b6f19c7aacaaa127f Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Wed, 30 Dec 2015 15:34:56 +0800 Subject: [PATCH] Don't need NOT IN conditions when there are no primary keys found --- association.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/association.go b/association.go index 1dce7a00..dfc79598 100644 --- a/association.go +++ b/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" {