我创建了一个模型类,希望可以希望可以和其他表关联起来。我的字段名创建的是Id 截屏2022-05-22 上午2 40 09 ,但是在通过这个字段查询的时候,是查不到了,会提示 *Error 1054: Unknown column 'user_permissions.UserId' in 'where clause'

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: resokou

检查在线文档 https://gorm.io/zh_CN/docs/belongs_to.html

如果UserId是一个foreign key (User),那么它需要被命名为UserID,并且还需要添加User struct。

type User struct {
    ID ...
}

type UserPermission struct {
    ...
    UserID ...
    User 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: xrl12

我想在UserID存放用户id,但是我不希望使用外键进行关联

Comment From: xrl12

我希望UserId来存放用户id,但是并不希望使用外建进行关联

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