-
Notifications
You must be signed in to change notification settings - Fork 94
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
Map Merging Preventing Updates #323
Comments
Hm that's does not look good. Out of the box I know no way around it. I think for a quick win we need to implement the possibility for the user to change the "merging" behaviour. I see if I can get to it soon. |
👍 Looking forward to it. |
Looks like the root of the problem is this line from the json.Unmarshal documentation:
I can see this being in the code:
Based on that, one approach might be to check each struct field to see if it's a map, and if so, set the map to Actually, we should probably nil the maps coming from the FindOne() call instead. |
@bbergshaven no sorry, there was no change in that regard - I still think the correct way to fix this, is to let the user manually implement/overwrite the merging behavior, what do you think? |
Thanks for the swift reply.
This seems to work great and solve our problems. |
I have a struct similar to the following:
I've satisfied the FindOne, Update, Delete, and Create methods on this type. I can successfully create, delete, and read a device, but I'm having a problem with the Tags field when Updates are processed.
Both the Device "d" and the "obj" provided by api2go contain the updated fields. Unfortunately, api2go is pulling any existing data from my database, and overwriting that struct with the struct provided by the client. For example, if the database contains:
and I send an update with this data:
The tags section get merged instead of overwritten. I end up with:
I've confirmed this by checking the obj and d variables before I do any database interactions. This might be related to #148
Is there any way I can prevent that map from being merged instead of overwritten?
The text was updated successfully, but these errors were encountered: