Skip to content

Commit

Permalink
fix: return error when use dest with has-many/many-to-many
Browse files Browse the repository at this point in the history
Close #606
  • Loading branch information
j2gg0s committed Jan 3, 2025
1 parent 4505099 commit 8296774
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions query_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8296774

Please sign in to comment.