登录
首页 >  Golang >  Go问答

GORM FirstOrCreate 不更新布尔值

来源:stackoverflow

时间:2024-03-18 19:30:28 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知识!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>