From 829677486b502e6d5d2ae37814488ae9f2c7386e Mon Sep 17 00:00:00 2001 From: j2gg0s Date: Fri, 3 Jan 2025 13:01:48 +0800 Subject: [PATCH] fix: return error when use dest with has-many/many-to-many Close #606 --- query_select.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/query_select.go b/query_select.go index a0f680ea..201bdce3 100644 --- a/query_select.go +++ b/query_select.go @@ -838,6 +838,14 @@ func (q *SelectQuery) scanResult(ctx context.Context, dest ...interface{}) (sql. if err != nil { return nil, err } + if len(dest) > 0 && q.tableModel != nil && len(q.tableModel.getJoins()) > 0 { + for _, j := range q.tableModel.getJoins() { + switch j.Relation.Type { + case schema.HasManyRelation, schema.ManyToManyRelation: + return nil, fmt.Errorf("When querying has-many or many-to-many relationships, you should use Model instead of the dest parameter in Scan.") + } + } + } if q.table != nil { if err := q.beforeSelectHook(ctx); err != nil {