hi Mark,
yes I am referring to e.g.
[[backendless.persistenceService of:[MY_CLASS class]] save:instance_of_my_class
and I get the same error indicated above:
“But I get the exemption: Unable to save object - invalid data type for properties -<field name>. You can change the property type in developer console.”
I’ll elaborate a bit.
Say I have a class in Objective-C with some fields that are Numeric (some of them are integers and some of them are double, but for the class everything is Numeric, right?).
Now, say that I create one of these objects, and I do not set a value for these numeric fields. At the first upload of the first object (calling save, when the database is still completely empty and doesn’t know the class), the object will get online and a schema will be dynamically defined. So based on the object properties (I’m assuming) you determine if you should have strings, integers or other in the schema.
However for the object fields that I did not set, and are Numeric properties, the schema decides that those fields are of type INT. However those fields are not necessarily of type INT, as I wrote above they could be of type double. So the next time when instead of keeping the field empty I populate it, I cannot write the object (i.e. the save function returns the error above), because the schema thinks the field is an INT while it’s actually a double and I’m trying to send a double.
Is this clear? Basically the dynamic schema creation assumes Numerics are INT, but they might be double, and if you do not write any value in some attributes, this causes problems in successive calls to save.
My workaround to this is the following now: I first upload ONE object with ALL fields set (like a nonsense object that is used just to create the schema properly, by setting double where double will be later on), and then I can proceed with the regular logic of my app. This is not ideal but works, because since in the first object all fields are set, there is no risk that the schema misunderstands types.
I also tried to change type on the schema online since it can be edited, but when I set them to double then they go back to int, so for now I will stick to the workaround unless you have other ideas. The problem comes from the fact that I have a lot of non-compulsory fields in these objects.