Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.

When updating, pointers set to nil are ignored #108

Open
ahall opened this issue Apr 20, 2014 · 10 comments
Open

When updating, pointers set to nil are ignored #108

ahall opened this issue Apr 20, 2014 · 10 comments
Assignees
Labels
Milestone

Comments

@ahall
Copy link
Contributor

ahall commented Apr 20, 2014

I got:

type User struct {
Id int64 xorm:"id"
CreatedAt time.Time xorm:"created_at"
Username string xorm:"username"
Email string xorm:"email"
Fullname string xorm:"fullname"
Password string xorm:"password"
ApiKey string xorm:"api_key"
Active bool xorm:"active"
ActivationCode *string xorm:"activation_code"
ActivationCodeExpiry *time.Time xorm:"activation_code_expiry"
ForgotPassCode *string xorm:"forgotpass_code"
ForgotPassCodeExpiry *time.Time xorm:"forgotpass_code_expiry"
}

user.Active = true
user.ActivationCode = nil
user.ActivationCodeExpiry = nil

session.Id(user.Id).UseBool().Update(user)
session.Commit()

I'd assume it would issue a SET activation_code_expiry = null and activation_code = null but it just seems to ignore them.

Also seems to ignore active unless I explicitly set .UseBool() which I dont see why is not the default. Many people are gonna fall into this trap I think.

@lunny
Copy link
Member

lunny commented Apr 21, 2014

When Update, default it will update the non-blank field, for example: 0, "", nil and bool. If you want to update some fields, you must explicit it on these functions:

Cols("col1, col2") : only update the columns
AllCols() : update all fields of struct
MustCols() : auto detect fields and must update the special columns
UseBool() : auto detect fields and must update the bool columns

@ahall
Copy link
Contributor Author

ahall commented Apr 21, 2014

Ok this starts making sense when I start thinking about this. Closing this. Just think we must document things a bit better.

@ahall ahall closed this as completed Apr 21, 2014
@ahall
Copy link
Contributor Author

ahall commented May 15, 2014

I been trying this and when doing:

issue.Resolved = false
issue.ResolvedAt = nil
issue.ResolvedComment = ""

state.DbSession.Id(issue.Id).AllCols().Update(issue)

Updates resolved and resolved_comment, but does not set resolved_at to null in the database. However: state.DbSession.Id(issue.Id).Cols("resolved_at", "resolved", "resolved_comment").Update(issue)

Does exactly what I want. Is is possible AllCols() is buggy and is ignoring null values?

@ahall ahall reopened this May 15, 2014
@lunny lunny added the bug label May 15, 2014
@lunny
Copy link
Member

lunny commented May 15, 2014

OK. I will test and fix it.

@ahall
Copy link
Contributor Author

ahall commented May 30, 2014

Hi @lunny, where did you get to with this?

@lunny
Copy link
Member

lunny commented May 31, 2014

I'm work on it now.

@ahall
Copy link
Contributor Author

ahall commented May 31, 2014

Thanks @lunny. Let me know and I'll test it for you.

@ahall
Copy link
Contributor Author

ahall commented Jun 11, 2014

Hi @lunny, any update yet?

@lunny
Copy link
Member

lunny commented Jun 12, 2014

It still not be resolved.

@lunny lunny added this to the v0.5 milestone Sep 7, 2014
@lunny lunny self-assigned this Sep 7, 2014
@lunny lunny modified the milestones: v0.5, v0.6 Oct 12, 2016
@xwjdsh
Copy link
Contributor

xwjdsh commented Dec 3, 2017

I tested and cannot recur this issue.

Fixed already?

@lunny lunny modified the milestones: 0.7, 0.8 Apr 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants