GORM Playground Link
https://github.com/go-gorm/playground/pull/480
Description
In gorm V1 , the value of the ignored field gorm:"-" will changed after update. In gorm V2 now , the value will not changed. Is this behavior change a bug ? If not , is there a writing style to get results like V1 ? Thanks so much !
Comment From: a631807682
https://gorm.io/docs/models.html#Fields-Tags
| Tag Name | Description |
| <- | set field’s write permission, <-:create create-only field, <-:update update-only field, <-:false no write permission, <- create and update permission |
Comment From: XBreath
@a631807682 Thanks for the reply !
But it doesn't work. 'age' does not exist in table.
if use '<-:false', will got same results(not updated).
if use '<-create' or '<-update', the sql execution will failed.
ERROR: column "age" of relation "user" does not exist (SQLSTATE 42703)
Comment From: a631807682
you should set read permission
| Tag Name | Description |
| -> | set field’s read permission, ->:false no read permission |
Comment From: XBreath
@a631807682 Thanks for the reply !! I have try the read permission tags '->' and '->:false'. but it doesn't work. the value in struct is not updated.
Comment From: a631807682
...
Age uint `gorm:"->:false;<-:update"`
doesn't this work?
Comment From: XBreath
``go ... Age uintgorm:"->:false;<-:update"`doesn't this work? ```
The value of Age in struct have changed after Update().
But the sql execution will failed.
ERROR: column "age" of relation "user" does not exist (SQLSTATE 42703)
[rows:0] UPDATE "user" SET "updated_at"='2022-05-30 19:10:01.058',"age"=18 WHERE "id" = 453
Comment From: a631807682
@XBreath The problem age not exists in table, you are not using AutoMigrate? you need to create this field on the database
Comment From: XBreath
yes, not using AutoMigrate() in my test.
But in V1 , using gorm: "-", will not create this field in table.
so age not exists in table. now v1 need to upgrade to V2.
using AutoMigrate() and gorm:"->:false;<-:update" will create this field in table.
Is there a way without creating ignored field like "Age"? @a631807682
Comment From: a631807682
ignore this field, - no read/write permission, -:migration no migrate permission, -:all no read/write/migrate permission
Comment From: XBreath
use this like https://github.com/go-gorm/playground/pull/480, the value of age in struct will not update after use Update(). Is this a problem?