Retriving groups related to Current User

Hi, so I have groups related to differente users, and a single user can have multiple groups. This is done with relations where 1 group is to N users. How can I get the groups that which a user is currently on?

You do it with an API request sent to the Groups table with the following where clause:

users.objectId = 'objectId of the user for which to get groups

like this mark?

String whereClause = "users.objectId = " + ApplicationClass.user.getUserId();

DataQueryBuilder queryBuilder = DataQueryBuilder.create();
queryBuilder.setWhereClause(whereClause);
queryBuilder.setGroupBy("groupName");

Backendless.Persistence.of(Group.class).find(queryBuilder, new AsyncCallback<List<Group>>() {
    @Override
    public void handleResponse(List<Group> response) {

        ApplicationClass.groups = response;

        myAdapter = new GroupAdapter(ChooseGroup.this, response);
        rvList.setAdapter(myAdapter);
    }

    @Override
    public void handleFault(BackendlessFault fault) {
        Toast.makeText(ChooseGroup.this, "SomethingWentWrong", Toast.LENGTH_SHORT).show();
    }
});

}

it’s giving me the SomethingWentWrong…

No, first of all the whereClause is wrong. The objectId is a string column, so the value must be in quotes:

String whereClause = "users.objectId = '" + ApplicationClass.user.getUserId() + "'" ;

Second is you do not need to use the setGroupBy method, it is used only with aggregate functions.

Regards,
Mark

.

1 Like

Hi mark, I’ve got another doubt. This group has a relation 1:1 to a Feed, and the feed has a relation 1:N posts, how can I get this posts having the groupObjectId ???