fixed changing slices
This commit is contained in:
@@ -347,7 +347,7 @@ func (api *API) collectionPutHandler(m mgocrud.ModelInterface) gin.HandlerFunc {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// apply newM on orgM and record changes for db update
|
// apply newM on orgM and record changes for db update, only first level for now
|
||||||
changes := bson.M{}
|
changes := bson.M{}
|
||||||
newMStruct := reflect.Indirect(reflect.ValueOf(newM))
|
newMStruct := reflect.Indirect(reflect.ValueOf(newM))
|
||||||
orgMStruct := reflect.Indirect(reflect.ValueOf(orgM))
|
orgMStruct := reflect.Indirect(reflect.ValueOf(orgM))
|
||||||
@@ -355,7 +355,9 @@ func (api *API) collectionPutHandler(m mgocrud.ModelInterface) gin.HandlerFunc {
|
|||||||
field := newMStruct.Field(i)
|
field := newMStruct.Field(i)
|
||||||
fieldT := newMStruct.Type().Field(i)
|
fieldT := newMStruct.Type().Field(i)
|
||||||
|
|
||||||
if field.Kind() == reflect.Ptr && !field.IsNil() {
|
if (field.Kind() == reflect.Ptr || field.Kind() == reflect.Slice) &&
|
||||||
|
!field.IsNil() {
|
||||||
|
|
||||||
// apply naming conventions of mgo for changeset
|
// apply naming conventions of mgo for changeset
|
||||||
tag := fieldT.Tag.Get("bson")
|
tag := fieldT.Tag.Get("bson")
|
||||||
if tag == "" && !strings.Contains(string(fieldT.Tag), ":") {
|
if tag == "" && !strings.Contains(string(fieldT.Tag), ":") {
|
||||||
|
|||||||
Reference in New Issue
Block a user