So in my user table I have a field called “Subscriptions” which is a one-many relation with another table called Products.
I currently have code to describe the class which is auto generated using the online dashboard and looks like this:
$rootScope.Classes = {
Products: function Products( args ){
args = args || {};
this.resolution = args.resolution || null;
this.objectId = args.objectId || null;
this.created = args.created || null;
this.category = args.category || null;
this.tpn = args.tpn || null;
this.barcode = args.barcode || null;
this.status = args.status || null;
this.count = args.count || null;
this.ownerId = args.ownerId || null;
this.description = args.description || null;
this.updated = args.updated || null;
this._private_relations = [];
this._private_geoRelations = [];
this._private_dates = [
"created",
"updated"];
this.___class = "Products";
var storage = Backendless.Persistence.of( Products );
this.save = function ( async )
{
cleanPrivateRelations(this);
storage.save( this, async );
};
this.remove = function ( async )
{
var result = storage.remove( this, async );
this.objectId = null;
return result;
};
this._private_describeClass = function(){
return Backendless.Persistence.describe(this.___class);
};
}
}
I also have code which I need to save a new “Product” and add to the “Subscriptions” field of the user object.
save() {
console.log('Barcode: ' + this.barcode);
console.log('Description: ' + this.description);
console.log('Category: ' + this.category);
console.log('TPN: ' + this.tpn);
var _product: window.Classes.Products = new window.Classes.Products({
barcode: this.barcode,
description: this.description,
category: this.category,
tpn: this.tpn
});
// Save and update user field here...
}
All the console.logs work correctly and the object is created successfully in the _product variable.
I’ve currently tried:
var user = Backendless.UserService.getCurrentUser();
user["subscriptions"].push(_product);
debugger;
Backendless.UserService.update( user );
Which is described at https://backendless.com/documentation/users/js/users_update_user_properties.htm
However this gives an error of “error: Saved related data contains inconsistent properties definitions. Please, make sure all related objects contain the same properties set or define all needed properties from console first” but all the properties are correct as far as I am aware?
As you can see from the attached, the only thing I can think is that it is not set up correctly as an object like the rest but instead shows as a Products object? The Products object does have an object id and it is in the database when I look in the browser so that part is saving correctly.
Anyone have any ideas?