2016-01-02 58 views
0

我有這樣的表結構試圖獲取多個數據的所有那些有關表 -抓取關係數據的Android Parse.com

enter image description here

我有類(ProfileCateGory對象)的名單和內簡介日期的每一個類別列表(ProfileData對象)與有瀏覽次數(ProfileViewCount對象

我是新來這個Parse.com我試試這樣 -

ParseQuery<ParseObject> query = ParseQuery.getQuery("ProfileData"); 
    query.whereEqualTo("profileName", "Profile"); 

    try { 
     for (int i = 0; i < query.count(); i++) { 
      query.getFirstInBackground(new GetCallback<ParseObject>() { 
       public void done(ParseObject object, ParseException e) { 
        if (object == null) { 
         Log.d("ProfileData", "Error: " + e.getMessage()); 
        } else { 
         Log.d("TAG", "Name: " + object.get("profileName").toString()); 
        } 
       } 
      }); 
     } 
    } catch (Throwable t) { 

    } 

我只從ProfileData獲取一個數據。

回答

0

您可以使用relational-queries

對於你必須做出profileCode爲指針類型ProfileViewCounts

ParseQuery<ParseObject> innerQuery = ParseQuery.getQuery("ProfileData"); 
innerQuery.whereEqualTo("profileName", "Profile"); 

ParseQuery<ParseObject> query =ParseQuery.getQuery("ProfileViewCounts"); 
    query.whereMatchesQuery("profileCode", innerQuery); 
    query.getFirstInBackground(new GetCallback<ParseObject>() { 

     @Override 
     public void done(ParseObject objProfileViewCounts, ParseException e) { 
      // TODO Auto-generated method stub 

     } 
    }); 
+0

感謝您的回覆,但你可以看到我已經基本上3臺。您已加入ProfileData和ProfileViewCounts。但我怎樣才能加入ProfileCateGory ProfileData? – Anirban

+0

這個類型的問題[BoltsFramework](https://github.com/BoltsFramework/Bolts-Android#chaining-tasks-together)支持'parse.com'的用戶'bolt'庫, –

0

getFirstInBackground()是調用和返回只有一個項目。

要得到你需要做一個數組或更多OBJETS:

  //profile or id of user , you have to pass as a parameter 

      ParseQuery<ParseObject> query = ParseQuery.getQuery("ProfileData"); 
      query.whereEqualTo("profileName", Profile); 

      query.findInBackground(new FindCallback<ParseObject>() { 
       @Override 
       public void done(List<ParseObject> objects, ParseException e) { 


        if (e == null) { 

         for (int inP = 0; inP < objects.size(); inP++) { 

          String profileName = objects.get(inP).getString("profileName"); 


         } 


        } else { 

        } 


       }