0

Database Relationship

there is a group DYNAMICGROUPS -> having array of pointers column(members) -> that contains array of user's objectId. Now I want to apply query in DYNAMICGROUPS to get all the details of dynamicGroups and all the object details of individual pointers of members column. Right now I am doing from multiple queries but its creating issue : Synchronous issue code

final ArrayList<TempGroupClass> tempGroupList = new ArrayList<TempGroupClass>();
    ParseQuery<ParseUser> query = ParseUser.getQuery();
    query.whereEqualTo("username",
            SharedPreferencesClass.getUserName(context));
    query.findInBackground(new FindCallback<ParseUser>() {

        @Override
        public void done(List<ParseUser> arg0, ParseException arg1) {
            if (arg1 == null) {
                if(arg0.size() > 0) {
                Log.d(TAG, "getUpdatedRecordsFromParse");
                ParseQuery<ParseObject> query = ParseQuery.getQuery("DynamicGroup");
                ArrayList<String> array = new ArrayList<String>();
                array.add(arg0.get(0).getObjectId());
                query.whereContainedIn("members", array);
                query.include("code");
                query.include("members");
                query.findInBackground(new FindCallback<ParseObject>() {

                    @Override
                    public void done(List<ParseObject> arg0, ParseException arg1) {
                        if (arg1 == null) {
                            if (arg0.size() > 0) {
                                for (int i = 0; i < arg0.size(); i++) {
                                    TempGroupClass temp = new TempGroupClass();
                                    ArrayList<String>   friendListArray = new ArrayList<String>();
                                    **<!-- arg0.get(i).getList("members")   this is giving me array of pointers now  i want object details of every pointer but how ? -->**
                                    // now to get dynamic group members array
                                    // loop through every member and
                                    for (int j = 0; j < arg0.get(i).getList("members").size(); j++) {
                                        // here we are excluding our object id from members id recieved from parse
                                        if (!(SharedPreferencesClass.getUserObjectId(context)
                                            .equalsIgnoreCase(arg0.get(i).getList("members").get(j).toString()))) {
                                            // friendarraylist excluding our objectID
                                            friendListArray.add(arg0.get(i).getList("members").get(j).toString());
                                        }
                                    }
                                    temp.setParseObjectId(arg0.get(i).getObjectId());
                                    temp.setFriendObjectIdList(friendListArray);
                                    // now get information of groups from groupCode
                                    Log.d(TAG,"setFriendObjectIdList size:" + temp.getFriendObjectIdList().size());

                                    /****************now get  group code information start *******************/
                                    ParseObject objectCodeObj = new ParseObject("DynamicGroup");
                                    objectCodeObj = arg0.get(i).getParseObject("code");
                                    String groupTitle = objectCodeObj.getString("code");
                                    // Pointor Object value                                     Log.d(TAG,"GROUP CODE STRING  :" + groupTitle);
                                    Log.d(TAG, "GROUP CODE EXPIRES TIME :" + objectCodeObj.getDate("expires"));
                                    /*****now get  group code information stop ***********/
                                    // loop for testing purpose what we r getting in list
                                    for(int j = 0; j < temp.getFriendObjectIdList().size(); j++) {
                                        Log.d(TAG,"member id:"+temp.getFriendObjectIdList().get(j));
                                    }
                                    temp.setGroupTitle(groupTitle);
                                    temp.setExpires(objectCodeObj.getDate("expires"));
                                        tempGroupList.add(temp);
                                }
                                getRecords(tempGroupList);
                            } else {
                                Log.d(TAG, "DynamicGroup arg0.size else :" + arg0.size());
                            }
                        }
                        // Log.d(TAG,"returned Group List size 1:" + tempGroupList.size());
                    }
                });
            } else {
                Log.d(TAG,"user arg0.size:"+arg0.size());   
            }
        }
    }
});

if I'm doing like above method then I'm also getting issues in my next query so how should I write my query and get all object details at once and then save in local/temp ArrayList() ?

Table Structure :

DynamicGroup DynamicGroup

GroupCode GroupCode

User Table user table

1
  • As a warning, do not spam comments across the site asking people to answer your question. I just removed all of these after many of them were flagged. That's not a proper use of comments. Commented Jul 15, 2015 at 19:22

2 Answers 2

2

Your "members" column is not an array of Pointers, it's an array of string object id's. If you had actually set them up as pointers, this is a trivial single query with one include('members') constraint.

When saving objects to an array column, don't save the object id, save the whole object... it will be converted to a pointer.

You can manually edit your array, for example, changing:

["iHHyf1Rerw", "sFqTz7FHCJ", "fxZ0GXOtrn"]

to:

[{"__type":"Pointer","className":"_User","objectId":"iHHyf1Rerw"},{"__type":"Pointer","className":"_User","objectId":"sFqTz7FHCJ"},{"__type":"Pointer","className":"_User","objectId":"fxZ0GXOtrn"}]

If you have a large amount of data already misconfigured like this, you could use an adhoc background job to update all of them.

Sign up to request clarification or add additional context in comments.

3 Comments

but my question is how will i pass json to save this data ? from android @Fosco
I saved the whole PFUSer but on Parses website, it shows the text as you have it and not a clickable user pointer. Why is that? Do I need to define my column as being a pointer or leave it as an Array?
If it's an array column, it'll never be clickable, but it's still valid... Only pointer column types (pointing to one object) will be clickable to see the pointed-to object.
0

I think what @Fosco said about json is if you want to insert MANUALLY. From your code you should save to array the hole objects, not their id's.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.