I am trying to write a query that joins two of my MobileServiceTables in my Azure Cloud Portal.
Currently here is my code.
List<Post> followTable = mPostTable.where().field("userId").ne(mUser.getUserId()).orderBy("createdAt", QueryOrder.Descending).execute().get();
mPostTable.where().field("userId").ne(mUser.getUserId()).orderBy("createdAt", QueryOrder.Descending).execute().get();
final List<Post> returnTable = new ArrayList<Post>();
for(Post p : followTable){
if(doesFollowingExist(mUser.getUserId(), p.getId()).size() > 0
&& !doesFollowingExist(mUser.getUserId(),
p.getId()).get(0).isRemoved()){
returnTable.add(p);
p.setFollowed(true);
}
}
I first find all posts that the user did not write. Then, I run a quick test to see if the user has followed the post. If he has, then it will add it to a new list. However, this method of doing it requires me to look through every single post, then do the follow check on each one individual.
Obviously, this is the wrong way to do it and it takes forever. What I am asking is: How do I join these two tables so that I can get all posts that user has followed in one query? I cant seem to find a way to do it.