type User struct {
    ID string
}

如下代码生成的SQL:

user := &User{}
db.First(user, "123456")
SELECT * FROM `user` WHERE `user`.`id` = '123456' ORDER BY `user`.`id` LIMIT 1

如下代码生成的SQL:

user := &User{}
db.First(user, "16E88674CFB58578")
SELECT * FROM `user` WHERE 16E88674CFB58578 ORDER BY `user`.`id` LIMIT 1

这样的SQL错误了。

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: a631807682

Seems doc use cases are easily misunderstood, when the id is type string, we don't know if it's an primary key value or a query, so we should look at this part of the doc. https://gorm.io/docs/query.html#Retrieving-objects-with-primary-key

db.First(&user, "id = ?", "1b74413f-f3b8-409f-ac47-e8c062e3472a")// SELECT * FROM users WHERE id = "1b74413f-f3b8-409f-ac47-e8c062e3472a";

or do like this

user := &User{ID: "16E88674CFB58578"}
db.First(user)

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: li-jin-gou

@hagbei hello 可以参考一下文档 :kissing_heart: https://gorm.cn/zh_CN/docs/query.html#%E6%A0%B9%E6%8D%AE%E4%B8%BB%E9%94%AE%E6%A3%80%E7%B4%A2 Gorm db.First 生成错误的SQL