I have a currently logged in user , and i want an array of objects will be related with this user.
I have a relation between users table and MyObject table by the field MyObj at Users table.
On my app i create a new object, and i would like to add it to the MyObject table, to be related to the user.
I do it like this:
MyObject newObject = new MyObject();
loggedInUser.setProperty( "MyObj", new MyObject[] {newObject} );
Backendless.UserService.update(loggedInUser, AsyncCallback ...);
As i understand, it adds a single object to be related to User, correct ?
If i want to add an array of several MyObjects, as related to the User, i do the following:
m_objList = new ArrayList<MyObject>();
m_objList.add(newObject); // 1-st obj in array
m_objList.add(newObject); // 2-nd object in array
loggedInUser.setProperty( "MyObj", m_objList);
update
What if i already have the array related to the user (i loaded it from the server), and i just want to add one more object.
Should i do this again:
again ?
Does it uploads the whole array, or just the new item ?
I hope i’m clear, the question is how can i add an item to the related table without uploading the whole table ?
Hello Mark,
I’m asking that because i actually saw both behaviors.
I don’t know why this happen, my changes or maybe you had some updates on your side.
Several days ago i really had the behavior as you wrote, but then i got the following :
When i do setProperty with single element and then update, the new element is stored in the database with the relation, but all other objects that were related to the current user loose the relation (but stay in the DB), and i get only latest element is related.
When i add the whole array, then i see all the array’s elements related to the user.
My changes were that i changed the type of the dialog that collects the data for the new object.
I don’t think it is matter, because i’m still pulling out the current user from the Backendless service.