I think that developers should not have to worry about their variable being changed by library code and that platform’s functions should not have (unexpected) side-effects.
Do you agree?
Are you going to do something about that?
@plomteuxquentin That’s happening because you can’t update an object that includes a reference record (i.e. the updated object cannot include the “include” results).
if you want to keep the original object you should create a copy of it when you update:
But the code works as expect and it’s valid according to the documentation
When updating an item in a collection that has a reference field, set the value of the reference field to the referenced item’s _id value or the entire referenced item object .
Secondly, that’s not my point here. My point is that I should not have to worry that MY variables are mutated by Wix or any lib I use. Good practices dictate that a function should be as pure as possible (no side effect and agnostic of its environment), especially when you are not the owner of that parameter.
This is something I notice in this case, but it should be the rule for any public method develop by Wix
They are the one who should, indeed, do a copy before processing the update.
I think that is meant for the collection storage: If a given property does not exist in the collection field it is lost and not saved. That would be normal behaviour.
If you are right and it refers to the method argument, I still think that’s not good practice.
Moreover, that sentence is really confusing and not clear at all.
@plomteuxquentin you’re right. It would have made more sense if they’d cloned the object and mutate the copy under the hood and leave the original object as is.
It is not something that we should take care of.