I am making a two-player for Android using Parse.com. I'm determining which two players are in the game by introducing a Game table on Parse.com, with an Array of the userIds of the players of the game.
I need to query Parse.com for a list of all the games shared by two given players. I thought something like this would do the trick.
String[] userIds = new String[] {player1, player2};
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Game");
query.whereEqualTo("players", userIds);
The problem is, I don't know the order of the Array of players. So about half of the time, the order will be wrong I won't get the correct result from this query. I'll get that no game exists between the two players.
So my idea to solve this was to also query for a reversed array, then OR the two queries together.
String[] reversedUserIds = new String[] {player2, player1};
ParseQuery<ParseObject> query2 = new ParseQuery<ParseObject>("Game");
query2.whereEqualTo("players", reverseUserIds);
List<ParseQuery<ParseObject>> queryList = new ArrayList<ParseQuery<ParseObject>>();
queryList.add(query);
queryList.add(query2);
ParseQuery<ParseObject> mainQuery = ParseQuery.or(queryList);
However, when I run mainQuery.find(), I get an error that looks like this:
java.lang.IllegalArgumentException: invalid type for ParseObject: class [Ljava.lang.String;
Instead of simply returning a list of all the games that both players are playing with each other.
0 comments:
Post a Comment