Skip to content

Commit

Permalink
Merge pull request #1099 from j2gg0s/fix-return-err-when-use-scan-des…
Browse files Browse the repository at this point in the history
…t-with-has-many

fix: return error when use dest with has-many/many-to-many.
  • Loading branch information
j2gg0s authored Jan 6, 2025
2 parents a92a83e + 8296774 commit b50a0a5
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 @@ -849,6 +849,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 b50a0a5

Please sign in to comment.