You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Perhaps someone can help me out and point to what I am doing wrong.
I have a string field in a DB, it can be null, and setting it to null seemed to work when I was using a *string type. I have a record which has a value in the field, and I want to set it back to null. So, I switched to using sql.NullString. Per everything I can find on the Internet. This seems necessary as GORM will not include a field if the value is not null.
Now, when I want to change the value in the record this back to null, GORM isn't adding the field to the generated SQL:
Struct with the fields:
type Alias struct {
ID string `gorm:"primaryKey"`
FacilityId string
LinkId string
SchemeId sql.NullString
Alias string
CreatedAt time.Time
UpdatedAt time.Time
}
UPDATE `aliases` SET `alias`='WWALIAS',`updated_at`='2024-10-07 23:44:18.447' WHERE id = 'd0a0d9e0-ed47-4ed0-b146-6620e18b0566' and facility_id = '227f1c44-6ed7-41a1-9ee7-3b8bdbd8cf66'
Note the absence of the SchemeId (scheme_id) in the SQL. It clearly has a non-nil type, but I can't seem to see how to accomplish this.
And I would like to avoid pulling, then saving the record.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Perhaps someone can help me out and point to what I am doing wrong.
I have a string field in a DB, it can be null, and setting it to null seemed to work when I was using a *string type. I have a record which has a value in the field, and I want to set it back to null. So, I switched to using sql.NullString. Per everything I can find on the Internet. This seems necessary as GORM will not include a field if the value is not null.
Now, when I want to change the value in the record this back to null, GORM isn't adding the field to the generated SQL:
Struct with the fields:
Populated struct to use for .Updates()
Generated SQL
Note the absence of the
SchemeId
(scheme_id
) in the SQL. It clearly has a non-nil type, but I can't seem to see how to accomplish this.And I would like to avoid pulling, then saving the record.
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions