From 448d6a6baf23b6165a84b73bd9aee2a3728efa41 Mon Sep 17 00:00:00 2001 From: xing Date: Tue, 30 May 2023 23:49:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/relation.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/model/relation.go b/model/relation.go index 081338d..399a977 100644 --- a/model/relation.go +++ b/model/relation.go @@ -24,7 +24,7 @@ const ( // Relationship join table // -// RelationType HasOne| HasMany +// # RelationType HasOne| HasMany // // eg: hasOne, post has a user. ForeignKey is user's id , Local is post's userId field // @@ -81,7 +81,8 @@ func parseAfterJoin(fromTable string, ids [][]any, qq *QueryCondition, ship Rela ), }) if ship.Middle != nil && ship.Middle.Middle != nil { - return parseAfterJoin(tables[len(tables)-1], ids, qq, *ship.Middle) + r := parseAfterJoin(tables[len(tables)-1], ids, qq, *ship.Middle) + return ship.RelationType == HasMany || r } else { from := strings.Split(qq.From, " ") ww, ok := qq.Where.(SqlBuilder) @@ -107,7 +108,7 @@ func parseAfterJoin(fromTable string, ids [][]any, qq *QueryCondition, ship Rela qq.Fields = str.Join(from[len(from)-1], ".", "*", ",", tables[len(tables)-1], ".", ship.Middle.ForeignKey) } qq.In = ids - return ship.Middle.RelationType == HasMany + return ship.RelationType == HasMany || ship.Middle.RelationType == HasMany } }