Home >Backend Development >Golang >## Why are my Go-GORM struct fields returning default values despite a successful query?
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:
<code class="go">type Res struct { ID int Number int UserID int }</code>
Alternatively, you can specify mappings between database columns and struct fields:
<code class="go">type res struct { id int `gorm:"column:id"` number int `gorm:"column:number"` user_id int `gorm:"column:user_id"` }</code>
These adjustments will ensure proper field mapping and return accurate results from your query.
The above is the detailed content of ## Why are my Go-GORM struct fields returning default values despite a successful query?. For more information, please follow other related articles on the PHP Chinese website!