Accessing Query Results in Go-GORM Structures
You're facing an issue where the result of a query into a 'res' structure remains default values despite a successful query execution. This is related to naming conventions in Go-GORM.
To address this, you can either make your 'res' type publicly accessible with public fields:
type Res struct {
ID int
Number int
UserID int
}
Alternatively, you can specify mappings between database columns and struct fields:
type res struct {
id int `gorm:"column:id"`
number int `gorm:"column:number"`
user_id int `gorm:"column:user_id"`
}
These adjustments will ensure proper field mapping and return accurate results from your query.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3