Can't delete related data

Hi
I’m using custom class Seller which contains list type of related object: List<BackendlessUser>Followers;
It is okay to add new user item to Seller instance to Followers list and save it at cloud. But when i tried to delete user item at list, it was not work actually. I deleted item from Seller instance’s Follower(list), set a new Followers to Seller, and saved it. Bellows are my code that updating Seller’s Followers

public class AccentAction extends Thread {
private static final String TAG = "AccentActionThread";
String sid;
Context context;
int mark;
public AccentAction(String s, Context c, int m){
sid = s;
context = c;
mark = m; // 0: unfollowing - delete, 1: following - add
}


@Override
public void run() {
Seller sel = Backendless.Data.of(Seller.class).findById(sid);
if(sel == null) return;
List&lt;BackendlessUser&gt; followers = sel.getFollowers();
BackendlessUser me = Backendless.UserService.CurrentUser();
boolean changed = false;
if (followers == null) {
if (mark == 0) {
Log.v(TAG, "no need to delete element from list");
return;
}
followers = new ArrayList&lt;BackendlessUser&gt;();
followers.add(me);
Log.v(TAG, "set new list to seller with new list");
sel.setFollowers(followers);
changed = true;
} else {
if(mark == 1) {
boolean found = false;
for(BackendlessUser u : followers) {
if(u.getObjectId().equals(me.getObjectId())) {
found = true;
break;
}
}
if(!found) {
sel.getFollowers().add(me);
Log.v(TAG, "need to adding user to list");
changed = true;
}
}else{
for(int i =0; i<sel.getFollowers().size(); i++) {
if(sel.getFollowers().get(i).getObjectId().equals(me.getObjectId())) {
Log.v(TAG, "item found");
BackendlessUser u = sel.getFollowers().remove(i);
if(u==null) {
Log.e(TAG, "fail at deleting..");
}else{
changed = true;
Log.v(TAG, "deleting completed" + u.getObjectId());
}
break;
}
}
}
}//
if(changed) {
Seller seller = Backendless.Data.of(Seller.class).save(sel);
if(seller == null) {
Log.e(TAG, "Error at updating");
}else{
Log.v(TAG, "updating ends");
if(seller.getFollowers() != null) {
Log.v(TAG, "after list size" + String.valueOf(seller.getFollowers().size()));
}
}


}else{
Log.v(TAG, "no need to update");
}
}




}

At the line 66, i checked that after saved Seller instance has a reduce size of Followers(List<BackendlessUser). But real problem is that when i reload the seller object from cloud after enough time past from updating, the Seller’s Follow(list) size was same and the user was not deleted.
I tried to this job by using both Sync and Async call at Thread and Main Thread, but result is same… What am i doing wrong? Please help me.

I do not see how you load relations. Did you configure autoload for the “followers” column?

Yes, checked that box

Related relations are returned only in the find() operations. When you save an object, the result does not contain related objects.

I see, then the way i tried to delete BackendlessUser item from ‘Follower’ array is not right?.

It is okay to delete it like that. What I am saying is the “seller” object you get on line 60 will not have related data.

I understand. I tested this,

Backendless.Persistence.of(Seller.class).find(new AsyncCallback<BackendlessCollection<Seller>>() {
@Override
public void handleResponse(BackendlessCollection<Seller> collection) {
Seller sel = collection.getData().get(0);
sel.getFollowers().remove(0);
Backendless.Persistence.of(Seller.class).save(sel, new AsyncCallback<Seller>() {
@Override
public void handleResponse(Seller seller) {
Log.e(TAG, “test updating end”);
}

        @Override
        public void handleFault(BackendlessFault backendlessFault) {
            Log.e(TAG, "error at saving : " + backendlessFault.toString());
        }
    });
}

@Override
public void handleFault(BackendlessFault backendlessFault) {
    Log.e(TAG, "error at loading : " + backendlessFault.toString());
}

});
But in my web console, the result was same and no user at list’s index 0 was not deleted.

I tested relation data add and delete at list with another custom classes, All was fine. But only this case that related list has BackenlessUser objects was not working. Is it a authority problem of user table?

I just tried the same thing and it worked as expected. Are you sure you’re checking in console the same Seller object that is being updated?

Sure, the table has only one object now. At console i manually added 1 test ‘Seller’ row. Then i programmatically added 3 users to it’s ‘Followers’ list and saved from my mobile side. After about 5 minutes, i tried to delete 2 users from test ‘Seller’ object’s ‘Followers’ list. However by reloading test object’s list by find() operation from client side or checking it’s relation at the console, the result was same.

Can you show me your code what you’ve tested? I don’t know which part of my code is wrong. All i used related data works fine except this BackendlessUser related one.

Here’s the code I used to test:

Class Bar:

package com.mbaas;


public class Bar
{
  public String name;
}

Class Foo:

package com.mbaas;


import java.util.ArrayList;


public class Foo
{
  public String name;
  public ArrayList&lt;Bar&gt; bars;
}

Test code:
using findLast since I had multiple foo objects in the table and the last one was created using backendless console. The object had a collection of two “bar” objects. After I ran the code, one of the bar objects was deleted (verified in console). The code uses sync API so I had to run it in a new thread to avoid problems with the main UI thread:

    Foo foo = Backendless.Data.of( Foo.class ).findLast();
    foo.bars.remove( 0 );
    Backendless.Data.of( Foo.class ).save( foo );

Hi Mark, I’m having the same issue here where I’m removing items (Recipe objects) from a List in my main object (Party object) but it’s not updating on the server. The interesting thing is, I’m seeing the correct amount of (Recipe) items in my List when my main Object (Party) returns, but again, no change on the server. My code looks similar to yours:

public class Party extends ModelObject { 
 ... 
 private List&lt;Recipe&gt; menuItems = new ArrayList&lt;&gt;(); 
 ... 
}


public class Recipe extends ModelObject { 
 ... 
 private List&lt;Ingredient&gt; ingredients; 
 private String language; 
 ... 
}


Backendless.Persistence.of(Party.class).save(mParty, new AsyncCallback&lt;Party&gt;() { 
 
 @Override 
 public void handleResponse(Party party) { 
 PartyPlannerLog.v(WHOAMI, "Party Saved"); 
 } 
 
 @Override 
 public void handleFault(BackendlessFault fault) { 
 Toast.makeText(partyViewActivity, "Error saving party!", Toast.LENGTH_SHORT).show(); 
 } 
});


So in the handleResponse code block, the menuItems List contains the correct items, however, i’m not seeing the change on the server. Any ideas?

Btw, I can add Recipe items to the list without a problem, but removing them is when I don’t see the change on the server.

Yeah I’m experiencing this problemo as well…

Just double checked the functionality in the topic.

I have an Order table and ShoppingItem table, with one order to many items relation
In the test I retrieve first order from the database, print the information about order items, delete first item from the list, save order and print the information about order items again. Both versions (client and server).

All works as expected.

Here is the screenshot with the code

http://support.backendless.com/public/attachments/3cb2156a70d75190d63431aaab1168aa.png</img>
If you still experience a troubles with relation removal, please, create a MINIMAL set of code demonstrating a problem and send it to the support@backendless.com

I tried adding the “__meta” property to my custom Class (I’m doing this in Flex/AIR), and that did the trick. I guess the server needs some data from there in order to go through with the update.