Gorm returns zero value if is camel case

Hello so im doing a query, it returns all values but userId is always 0 value, but if i remove camel case and set it like userid it works, heres my model and output.

Note:

I dont want to use *gorm.Model

My Model

 package students
 // import "gorm.io/gorm"
 type Students struct {
     // *gorm.Model
     Id     int    `json:"id"`
     UserId int    `json:"userId"`
     Name   string `json:"name"`
     Age    int    `json:"age"`
 }

Output.

[
   {
     "id": 1,
     "userId": 0,
     "name": "Alejandro Castillo",
     "age": 26
   },
   {
     "id": 2,
     "userId": 0,
     "name": "Doom Metal",
     "age": 44
   }
 ]

Try adding gorm tag

gorm:"column:{column name in db}"

1 Like

Hello thanks, it work like this.

package students
// import "gorm.io/gorm"

type Students struct {
    // *gorm.Model
    Id     int    `json:"id"`
    UserId int    `gorm:"column:userId"`
    Name   string `json:"name"`
    Age    int    `json:"age"`
}