Generics API and struct based query keys?
type:question
<!-- DON'T CHANGE THE TEMPLATE -->
## Your Question
<!-- Most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io, ✨ Search Before Asking ✨ -->
<!-- Ask your question in English, minimalist example is highly recommended, please `Report a bug` for bugs -->
Does the Generics API support querying using struct-based selectors?
The example given for say, selecting an object by primary key involves using the string based selector e.g.
```go
user, err := gorm.G[User](db).Where("id = ?", "10").First(ctx)
```
Which requires me to know the assigned name of the field in the database. I would expect to be able to do something more like this:
```go
user, err := gorm.G[User](db).Where(&User{Id: 10}).First(ctx)
```
Which means that the field identity to be selected is determined from the model defined in my code. There's no explanation in the documentation as to why this split exists, or when one approach or the other should be picked.
## The document you expected this should be explained
<!-- The document link you expected this question should be explained in our [official documents site](https://gorm.io) -->
https://gorm.io/docs/query.html
## Expected answer
<!-- What you want -->
Either the documentation to confirm that the generics API doesn't support struct-based querying, an example of how it's done if it works, AND a clear explanation over why the Generics API should be preferred over the Traditional API given the split.
0 条评论