From 031495d5ac8d86a319c36fbf9a4fed039f348469 Mon Sep 17 00:00:00 2001 From: Xi Xinjie Date: Sat, 24 Sep 2022 13:04:29 +0800 Subject: [PATCH 1/2] fix eager creation for associations by adding where clause (#607) --- executors.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/executors.go b/executors.go index a2905436..2d4443bc 100644 --- a/executors.go +++ b/executors.go @@ -273,7 +273,8 @@ func (c *Connection) Create(model interface{}, excludeColumns ...string) error { if IsZeroOfUnderlyingType(id) { return c.Create(m.Value) } - exists, errE := Q(c).Exists(i) + + exists, errE := Q(c).Where("id = ?", id).Exists(i) if errE != nil || !exists { return c.Create(m.Value) } From ec95bc4cca88478e97dee0924d78f0e0b63a40cb Mon Sep 17 00:00:00 2001 From: Yonghwan SO Date: Sat, 24 Sep 2022 14:13:18 +0900 Subject: [PATCH 2/2] use WhereID instead 'id = ?' --- executors.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executors.go b/executors.go index 2d4443bc..dfda8ebc 100644 --- a/executors.go +++ b/executors.go @@ -274,7 +274,7 @@ func (c *Connection) Create(model interface{}, excludeColumns ...string) error { return c.Create(m.Value) } - exists, errE := Q(c).Where("id = ?", id).Exists(i) + exists, errE := Q(c).Where(m.WhereID(), id).Exists(i) if errE != nil || !exists { return c.Create(m.Value) }