I'm using gorm(GoLang) with PostgreSQL. recently I've decided to use association with gorm in order to save time and for best practice...
So the issue is that I want to update a model without overwriting all his fields.
for example' I have this structs:
type Car struct {
gorm.Model
CarModels []CarModel `json:"car_models"`
Foo string `json:"foo"`
}
type CarModel struct {
gorm.Model
Name string `json:"name"`
Bar string `json:"-"`
CarID uint `json:"car_id"`
}
- The user can only see the car model name and car_id.
- The user changed the car model name and asked to save it.
- I want to save the changes to DB and Gorm
db.Update()
- so I save the Car model (not the CarModel !!!) because they are associated
And the issue is that field Bar is empty on DB... because I didn't return it to the client...
I've tried to find an answer here and on Gorm docs and didn't find any...
Does someone have any idea how to handle this problem?