Answer the question
In order to leave comments, you need to log in
Why is db.Find eating one of the table values?
Good afternoon. I read in the official documentation that db.find is essentially select * from, but using select * from through MySQL I get .
Whereas using db.Find in the code gives me
a Question. Why does db.Find eat userId and instead of the required 7, it always returns 0?
Structure in code:
type Post struct {
ID int `gorm:"primaryKey"`
UserId int `json:"userId"`
Title string `json:"title"`
Body string `json:"body"`
}
DB table:
Columns :
id int PK
userId int
title varchar(100)
body varchar(250)
PS I apologize wildly for the wildness of the second screenshot, here is an example in letters: "ID": 61, "userId": 0, "title": "voluptatem doloribus consectetur est ut ducimus", "body": "ab nemo optio odio\ndelectus tenetur corporis similique nobis repellendus rerum omnis facilis\nvero blanditiis debitis in nesciunt doloribus dicta dolores\nmagnam minus velit"
Answer the question
In order to leave comments, you need to log in
99%, it's about the field names
If you extract data from the database into the Post structure, add db:"userId" there to get something like this
UserId int `json:"userId" db:"userId"`
or for gorm
UserId int `json:"userId" gorm:"column:userId"`
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question