Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch update UpdateNotZero while use_zero flag #1580

Conversation

ramezhanna
Copy link

patch UpdateNotZero function neglect use_zero flag in fields.

patch UpdateNotZero function neglect use_zero flag in fields.
@vmihailenco
Copy link
Member

This would be a pretty substantial change that limits UpdateNotZero usability for fields with use_zero flag. It can be that current behavior is desired. There is following sentence in changelog

UpdateNotNull is renamed to UpdateNotZero. As previously it omits zero Go values, but it does not take in account if field is nullable or not.

@ramezhanna
Copy link
Author

ramezhanna commented Apr 16, 2020

i think it will not limit UpdateNotZero as it partially update model it will behave the same in case use_zero flag is not set for example if you have a model:

type AdditionalContact struct {
	tableName       struct{}  `pg:"additional_contacts"`
	Id                     string    `pg:"id,pk,type:uuid,default:gen_random_uuid()"`
	AccountId        string    `pg:"account_id,type:uuid"`
	FirstName        string    `pg:"first_name"`
	LastName        string    `pg:"last_name"`
	IsEnabled        bool      `pg:"is_enabled,type:bool,use_zero"`
	SendAccountEmail bool      `pg:"send_account_email"`
	CreatedAt        time.Time `pg:"created_at"`
	UpdatedAt        time.Time `pg:"updated_at"`
}

and you want to set the IsEnabled to false only without updating the rest of the values with this change UpdateNotZero with produce the following query:
update object :

{
    "FirstName": "Takishi",
    "LastName": "Hamda",
    "Email": "t.hamada@main.com",
    "isEnabled": false,
    "SendAccountEmail": false
}
UPDATE additional_contacts AS "additional_contact" SET "first_name" = 'Takishi', "last_name" = 'Hamada', "email" = 't.hamada@main.com', "is_enabled" = FALSE, "updated_at" = '2020-04-16 08:51:01.544290498+00:00:00' WHERE "additional_contact"."id" = '132c0152-8e62-4f7a-9aa2-7cb5bcc48093'

@vmihailenco vmihailenco closed this Jun 9, 2020
@frederikhors
Copy link
Contributor

Same problem here, @vmihailenco.

I'm using UpdateNotZero() but sometimes I need to only "reset" a single column value and it would be useful to do it like this!

Please, can you reconsider?

@RamezMagdy Have you found another way to do it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants