2014-04-23 69 views
1

我在parse.com中找到了示例。我有2個對象:郵政和評論,在評論的對象有一個collumn:「父」指針發佈OBJ,我想加入他們的行列:parse.com(Unity)中的關係查詢

var query = ParseObject.GetQuery ("Comment"); 
// Include the post data with each comment 
query = query.Include("parent"); 
query.FindAsync().ContinueWith(t => { 
    IEnumerable<ParseObject> comments = t.Result; 
     // Comments now contains the last ten comments, and the "post" field 
     // contains an object that has already been fetched. For example: 
    foreach (var comment in comments) 
    { 

     // This does not require a network access. 
     string o= comment.Get<string>("content"); 
     Debug.Log(o); 
     try { 
      string post = comment.Get<ParseObject>("parent").Get<string>("title"); 
      Debug.Log(post); 


     } catch (Exception ex) { 
      Debug.Log(ex); 
     } 
    } 

}); 

它的工作! 然後,我有2個對象:用戶和Gamescore,在Gamescore對象都有一個collumn:「playerName」指針後OBJ我想加入他們太:

var query = ParseObject.GetQuery ("GameScore"); 
     query.Include ("playerName"); 
     query.FindAsync().ContinueWith (t =>{ 
      IEnumerable<ParseObject> result = t.Result; 
      foreach (var item in result) { 
       Debug.Log("List score: "); 
       int score = item.Get<int>("score"); 
       Debug.Log(score); 
       try { 
        var obj = item.Get<ParseUser>("playerName"); 
        string name = obj.Get<string>("profile"); 
        //string name = item.Get<ParseUser>("playerName").Get<string>("profile"); 

        Debug.Log(name); 

       } catch (Exception ex) { 
        Debug.Log(ex); 
       } 
      } 
     }); 

,但它不能正常工作,請幫助我!

+0

幫我。請。任何人? – Clay

回答

0

一個解決方案是確保您的ParseUser對象被正確提取。即:

var obj = item.Get<ParseUser>("playerName"); 
Task t = obj.FetchIfNeededAsync(); 
while (!t.IsCompleted) yield return null; 

然後你就可以做到這一點,而不必擔心:

string name = obj.Get<string>("profile"); 

但是,這將是解析另一個潛在的請求,這是不幸的。看來query.Include ("playerName")在Parse的Unity版本中工作不正常?

+0

非常感謝! 但我該怎麼做呢?因爲我想從User對象獲取數據! – Clay

1

你爲什麼不喜歡做的你做你的第一個例子如下:

query = query.Include ("playerName"); 

你只是 -

query.Include ("playerName"); 
0

我相信你應該使用多級包括:這在你的第一個查詢中就像.Include("parent.playerName")一樣。