-
Notifications
You must be signed in to change notification settings - Fork 755
When updating, pointers set to nil are ignored #108
Comments
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 |
Ok this starts making sense when I start thinking about this. Closing this. Just think we must document things a bit better. |
I been trying this and when doing: issue.Resolved = false 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? |
OK. I will test and fix it. |
Hi @lunny, where did you get to with this? |
I'm work on it now. |
Thanks @lunny. Let me know and I'll test it for you. |
Hi @lunny, any update yet? |
It still not be resolved. |
I tested and cannot recur this issue. Fixed already? |
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.
The text was updated successfully, but these errors were encountered: