Skip to content

Conversation

@hakanakyurek
Copy link

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

Changes the Row and Rows functions in the generic api to specify the generic type as the model for the db operations internally, similar to setCreateOrUpdateG or Exec.

User Case Description

When using Row() and Rows() functions in the traditional api the caller has to specify the Model to use in the db operations.

rows, err :=  db.Model(&User{}).Where("name = ?", "Alice").Rows()

However, in the generic api, I think the behaviour expected is that the generic api uses the generic types to do the operations without specifying the model in a separate step. Specifically:

rows, err := gorm.G[User](db).Where("name = ?", "Alice").Rows(ctx)

should successfully return the users that are named "Alice", instead we get:

/usr/local/go/src/runtime/proc.go:283 unsupported data type: <nil>
[0.306ms] [rows:0] SELECT * FROM  WHERE type = "1"
panic: runtime error: invalid memory address or nil pointer dereference
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x61 pc=0x104dc7a38]

since without caller specifying the model for the operation in a separate step, the Table remains empty.

@propel-code-bot
Copy link
Contributor

Align generics Row/Rows with inferred model binding

Updates the generics execution helpers so that Row() and Rows() automatically bind the generic type to the underlying statement via Model(r), matching the behavior of other generics operations that infer the model. Test coverage around TestGenericsRow is expanded to validate both raw SQL and query-builder scenarios now that the model is inferred automatically.

Key Changes

• Updated execG[T].Row() and execG[T].Rows() to call Model(r) before executing the query
• Expanded TestGenericsRow with additional raw and chained query cases to exercise the new inference behavior

Affected Areas

generics.go
tests/generics_test.go

This summary was automatically generated by @propel-code-bot

@hakanakyurek hakanakyurek changed the title feat: Row() and Rows() functions should automaticaly apply the generic type as model fix: Row() and Rows() functions should automaticaly apply the generic type as model Dec 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant