Answer the question
In order to leave comments, you need to log in
How to pass columns to orm.update if the number of columns is not known in advance?
type My_table struct {
Id int
Name string
Lastname string
}
o := orm.NewOrm()
field := My_table{Id: Id}
num, err := o.Update(&field, "name", "lastname")
func (o *orm) Update(md interface{}, cols ...string) (int64, error)
Answer the question
In order to leave comments, you need to log in
In general, everything turned out to be quite simple when you read the manuals carefully.
We make an array with the maximum number of columns that may need to be updated:
And then, depending on the condition, we reassign a slice with the necessary elements to it:
If we only need the "name" field:
And we substitute this array into the update function, with three points, which denote a variable number of arguments:num, err := o.Update(&device, str...)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question