GORM FirstOrCreate 不更新布尔值
时间:2024-03-18
浏览:303
作者:佚名
在使用 GORM 的 FirstOrCreate 方法更新模型时,对于布尔字段,该方法仅会将其更新为真值。为了解决此问题,可以使用 HidePricingFromProfile 字段类型,该类型会将布尔值存储为 SQL 中的 boolean 数据类型,并允许更新为真或假。
问题内容
在我的模型中,我有这样的字段:
hidepricingfromprofile bool `json:"hidepricingfromprofile"`
当我更新数据库中的模型时:
store.storage.db.
where("artist_account_id = ?", m.artistaccountid).
assign(model).
firstorcreate(m).
error
它仅将布尔字段更新为真值。
该字段在数据库中定义如下:
hide_pricing_from_profile boolean default false not null
解决方案
来自doc
HidePricingFromProfile *bool `json:"hidePricingFromProfile"`
好了,本文到此结束,带大家了解了《GORM FirstOrCreate 不更新布尔值》,希望本文对你有所帮助!关注golang学习网公众号,给大家分享更多Golang知识!
本文内容来源于互联网,如有侵权请联系删除。
近期热门
11.18
11.15
站内热门
最新文章
11.20
11.20
11.20
11.20
热门专题
