type JWTLoginRecord struct {
ID uint gorm:"primaryKey" json:"id;->"
UserID string gorm:"not null;index;type:char(32);<-:create" json:"user_id"
User User gorm:"foreignKey:UserId;references:UserId"
}
type User struct {
ID uint gorm:"primaryKey;<-:false"
UserId string gorm:"not null;type:char(32);unique;<-:create;" json:"user_id"
}
panic: invalid field found for struct user/models.JWTLoginRecord's field User: define a valid foreign key for relations or implement the Valuer/Scanner interface
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: hhniao
pkg\mod\gorm.io\gorm@v1.25.4\schema\relationship.go:520 when i debug, i dont know why this code running.
relation.primaryKeys = []string{"UserId"}
when i update code to:
User User gorm:"foreignKey:UserId;references:UserId"
it is work, any thing alright.
JWTLoginRecord.User NOT NIL, EVEN HAVE NO SPECIAL references.
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: hhniao
sorry, i was wrong. JWTLoginRecord.UserID it is not UserId
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 ✨